1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Contracts
; use Contracts
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Elists
; use Elists
;
34 with Fname
; use Fname
;
35 with Fname
.UF
; use Fname
.UF
;
36 with Freeze
; use Freeze
;
37 with Ghost
; use Ghost
;
38 with Impunit
; use Impunit
;
39 with Inline
; use Inline
;
41 with Lib
.Load
; use Lib
.Load
;
42 with Lib
.Xref
; use Lib
.Xref
;
43 with Namet
; use Namet
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Output
; use Output
;
48 with Par_SCO
; use Par_SCO
;
49 with Restrict
; use Restrict
;
50 with Rident
; use Rident
;
51 with Rtsfind
; use Rtsfind
;
53 with Sem_Aux
; use Sem_Aux
;
54 with Sem_Ch3
; use Sem_Ch3
;
55 with Sem_Ch6
; use Sem_Ch6
;
56 with Sem_Ch7
; use Sem_Ch7
;
57 with Sem_Ch8
; use Sem_Ch8
;
58 with Sem_Dist
; use Sem_Dist
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Util
; use Sem_Util
;
61 with Sem_Warn
; use Sem_Warn
;
62 with Stand
; use Stand
;
63 with Sinfo
; use Sinfo
;
64 with Sinfo
.CN
; use Sinfo
.CN
;
65 with Sinput
; use Sinput
;
66 with Snames
; use Snames
;
67 with Style
; use Style
;
68 with Stylesw
; use Stylesw
;
69 with Tbuild
; use Tbuild
;
70 with Uname
; use Uname
;
72 package body Sem_Ch10
is
74 -----------------------
75 -- Local Subprograms --
76 -----------------------
78 procedure Analyze_Context
(N
: Node_Id
);
79 -- Analyzes items in the context clause of compilation unit
81 procedure Build_Limited_Views
(N
: Node_Id
);
82 -- Build and decorate the list of shadow entities for a package mentioned
83 -- in a limited_with clause. If the package was not previously analyzed
84 -- then it also performs a basic decoration of the real entities. This is
85 -- required in order to avoid passing non-decorated entities to the
86 -- back-end. Implements Ada 2005 (AI-50217).
88 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
);
89 -- Common processing for all stubs (subprograms, tasks, packages, and
90 -- protected cases). N is the stub to be analyzed. Once the subunit name
91 -- is established, load and analyze. Nam is the non-overloadable entity
92 -- for which the proper body provides a completion. Subprogram stubs are
93 -- handled differently because they can be declarations.
95 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
);
96 -- Check whether the source for the body of a compilation unit must be
97 -- included in a standalone library.
99 procedure Check_No_Elab_Code_All
(N
: Node_Id
);
100 -- Carries out possible tests for violation of No_Elab_Code all for withed
101 -- units in the Context_Items of unit N.
103 procedure Check_Private_Child_Unit
(N
: Node_Id
);
104 -- If a with_clause mentions a private child unit, the compilation unit
105 -- must be a member of the same family, as described in 10.1.2.
107 procedure Check_Stub_Level
(N
: Node_Id
);
108 -- Verify that a stub is declared immediately within a compilation unit,
109 -- and not in an inner frame.
111 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
);
112 -- When a child unit appears in a context clause, the implicit withs on
113 -- parents are made explicit, and with clauses are inserted in the context
114 -- clause before the one for the child. If a parent in the with_clause
115 -- is a renaming, the implicit with_clause is on the renaming whose name
116 -- is mentioned in the with_clause, and not on the package it renames.
117 -- N is the compilation unit whose list of context items receives the
118 -- implicit with_clauses.
120 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
);
121 -- Generate cross-reference information for the parents of child units
122 -- and of subunits. N is a defining_program_unit_name, and P_Id is the
123 -- immediate parent scope.
125 function Has_With_Clause
128 Is_Limited
: Boolean := False) return Boolean;
129 -- Determine whether compilation unit C_Unit contains a [limited] with
130 -- clause for package Pack. Use the flag Is_Limited to designate desired
133 procedure Implicit_With_On_Parent
(Child_Unit
: Node_Id
; N
: Node_Id
);
134 -- If the main unit is a child unit, implicit withs are also added for
135 -- all its ancestors.
137 function In_Chain
(E
: Entity_Id
) return Boolean;
138 -- Check that the shadow entity is not already in the homonym chain, for
139 -- example through a limited_with clause in a parent unit.
141 procedure Install_Context_Clauses
(N
: Node_Id
);
142 -- Subsidiary to Install_Context and Install_Parents. Process all with
143 -- and use clauses for current unit and its library unit if any.
145 procedure Install_Limited_Context_Clauses
(N
: Node_Id
);
146 -- Subsidiary to Install_Context. Process only limited with_clauses for
147 -- current unit. Implements Ada 2005 (AI-50217).
149 procedure Install_Limited_Withed_Unit
(N
: Node_Id
);
150 -- Place shadow entities for a limited_with package in the visibility
151 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
153 procedure Install_Withed_Unit
154 (With_Clause
: Node_Id
;
155 Private_With_OK
: Boolean := False);
156 -- If the unit is not a child unit, make unit immediately visible. The
157 -- caller ensures that the unit is not already currently installed. The
158 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
159 -- is called when compiling the private part of a package, or installing
160 -- the private declarations of a parent unit.
162 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean);
163 -- This procedure establishes the context for the compilation of a child
164 -- unit. If Lib_Unit is a child library spec then the context of the parent
165 -- is installed, and the parent itself made immediately visible, so that
166 -- the child unit is processed in the declarative region of the parent.
167 -- Install_Parents makes a recursive call to itself to ensure that all
168 -- parents are loaded in the nested case. If Lib_Unit is a library body,
169 -- the only effect of Install_Parents is to install the private decls of
170 -- the parents, because the visible parent declarations will have been
171 -- installed as part of the context of the corresponding spec.
173 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
);
174 -- In the compilation of a child unit, a child of any of the ancestor
175 -- units is directly visible if it is visible, because the parent is in
176 -- an enclosing scope. Iterate over context to find child units of U_Name
177 -- or of some ancestor of it.
179 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean;
180 -- When compiling a unit Q descended from some parent unit P, a limited
181 -- with_clause in the context of P that names some other ancestor of Q
182 -- must not be installed because the ancestor is immediately visible.
184 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean;
185 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
186 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
187 -- a library spec that has a parent. If the call to Is_Child_Spec returns
188 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
189 -- compilation unit for the parent spec.
191 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
192 -- Parent_Spec is non-empty, this is also a child unit.
194 procedure Remove_Context_Clauses
(N
: Node_Id
);
195 -- Subsidiary of previous one. Remove use_ and with_clauses
197 procedure Remove_Limited_With_Clause
(N
: Node_Id
);
198 -- Remove from visibility the shadow entities introduced for a package
199 -- mentioned in a limited_with clause. Implements Ada 2005 (AI-50217).
201 procedure Remove_Parents
(Lib_Unit
: Node_Id
);
202 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
203 -- contexts established by the corresponding call to Install_Parents are
204 -- removed. Remove_Parents contains a recursive call to itself to ensure
205 -- that all parents are removed in the nested case.
207 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
);
208 -- Reset all visibility flags on unit after compiling it, either as a main
209 -- unit or as a unit in the context.
211 procedure Unchain
(E
: Entity_Id
);
212 -- Remove single entity from visibility list
215 -- A dummy procedure, for debugging use, called just before analyzing the
216 -- main unit (after dealing with any context clauses).
218 --------------------------
219 -- Limited_With_Clauses --
220 --------------------------
222 -- Limited_With clauses are the mechanism chosen for Ada 2005 to support
223 -- mutually recursive types declared in different units. A limited_with
224 -- clause that names package P in the context of unit U makes the types
225 -- declared in the visible part of P available within U, but with the
226 -- restriction that these types can only be used as incomplete types.
227 -- The limited_with clause does not impose a semantic dependence on P,
228 -- and it is possible for two packages to have limited_with_clauses on
229 -- each other without creating an elaboration circularity.
231 -- To support this feature, the analysis of a limited_with clause must
232 -- create an abbreviated view of the package, without performing any
233 -- semantic analysis on it. This "package abstract" contains shadow types
234 -- that are in one-one correspondence with the real types in the package,
235 -- and that have the properties of incomplete types.
237 -- The implementation creates two element lists: one to chain the shadow
238 -- entities, and one to chain the corresponding type entities in the tree
239 -- of the package. Links between corresponding entities in both chains
240 -- allow the compiler to select the proper view of a given type, depending
241 -- on the context. Note that in contrast with the handling of private
242 -- types, the limited view and the non-limited view of a type are treated
243 -- as separate entities, and no entity exchange needs to take place, which
244 -- makes the implementation much simpler than could be feared.
246 ------------------------------
247 -- Analyze_Compilation_Unit --
248 ------------------------------
250 procedure Analyze_Compilation_Unit
(N
: Node_Id
) is
251 procedure Check_Redundant_Withs
252 (Context_Items
: List_Id
;
253 Spec_Context_Items
: List_Id
:= No_List
);
254 -- Determine whether the context list of a compilation unit contains
255 -- redundant with clauses. When checking body clauses against spec
256 -- clauses, set Context_Items to the context list of the body and
257 -- Spec_Context_Items to that of the spec. Parent packages are not
258 -- examined for documentation purposes.
260 ---------------------------
261 -- Check_Redundant_Withs --
262 ---------------------------
264 procedure Check_Redundant_Withs
265 (Context_Items
: List_Id
;
266 Spec_Context_Items
: List_Id
:= No_List
)
270 procedure Process_Body_Clauses
271 (Context_List
: List_Id
;
274 Used_Type_Or_Elab
: out Boolean);
275 -- Examine the context clauses of a package body, trying to match the
276 -- name entity of Clause with any list element. If the match occurs
277 -- on a use package clause set Used to True, for a use type clause or
278 -- pragma Elaborate[_All], set Used_Type_Or_Elab to True.
280 procedure Process_Spec_Clauses
281 (Context_List
: List_Id
;
284 Withed
: out Boolean;
285 Exit_On_Self
: Boolean := False);
286 -- Examine the context clauses of a package spec, trying to match
287 -- the name entity of Clause with any list element. If the match
288 -- occurs on a use package clause, set Used to True, for a with
289 -- package clause other than Clause, set Withed to True. Limited
290 -- with clauses, implicitly generated with clauses and withs
291 -- having pragmas Elaborate or Elaborate_All applied to them are
292 -- skipped. Exit_On_Self is used to control the search loop and
293 -- force an exit whenever Clause sees itself in the search.
295 --------------------------
296 -- Process_Body_Clauses --
297 --------------------------
299 procedure Process_Body_Clauses
300 (Context_List
: List_Id
;
303 Used_Type_Or_Elab
: out Boolean)
305 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
311 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean;
312 -- In an expanded name in a use clause, if the prefix is a renamed
313 -- package, the entity is set to the original package as a result,
314 -- when checking whether the package appears in a previous with
315 -- clause, the renaming has to be taken into account, to prevent
316 -- spurious/incorrect warnings. A common case is use of Text_IO.
322 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean is
324 return Entity
(N
) = P
325 or else (Present
(Renamed_Object
(P
))
326 and then Entity
(N
) = Renamed_Object
(P
));
329 -- Start of processing for Process_Body_Clauses
333 Used_Type_Or_Elab
:= False;
335 Cont_Item
:= First
(Context_List
);
336 while Present
(Cont_Item
) loop
338 -- Package use clause
340 if Nkind
(Cont_Item
) = N_Use_Package_Clause
343 -- Search through use clauses
345 Use_Item
:= First
(Names
(Cont_Item
));
346 while Present
(Use_Item
) and then not Used
loop
348 -- Case of a direct use of the one we are looking for
350 if Entity
(Use_Item
) = Nam_Ent
then
353 -- Handle nested case, as in "with P; use P.Q.R"
360 -- Loop through prefixes looking for match
363 while Nkind
(UE
) = N_Expanded_Name
loop
364 if Same_Unit
(Prefix
(UE
), Nam_Ent
) then
379 elsif Nkind
(Cont_Item
) = N_Use_Type_Clause
380 and then not Used_Type_Or_Elab
382 Subt_Mark
:= First
(Subtype_Marks
(Cont_Item
));
383 while Present
(Subt_Mark
)
384 and then not Used_Type_Or_Elab
386 if Same_Unit
(Prefix
(Subt_Mark
), Nam_Ent
) then
387 Used_Type_Or_Elab
:= True;
393 -- Pragma Elaborate or Elaborate_All
395 elsif Nkind
(Cont_Item
) = N_Pragma
397 Nam_In
(Pragma_Name_Unmapped
(Cont_Item
),
398 Name_Elaborate
, Name_Elaborate_All
)
399 and then not Used_Type_Or_Elab
402 First
(Pragma_Argument_Associations
(Cont_Item
));
403 while Present
(Prag_Unit
) and then not Used_Type_Or_Elab
loop
404 if Entity
(Expression
(Prag_Unit
)) = Nam_Ent
then
405 Used_Type_Or_Elab
:= True;
414 end Process_Body_Clauses
;
416 --------------------------
417 -- Process_Spec_Clauses --
418 --------------------------
420 procedure Process_Spec_Clauses
421 (Context_List
: List_Id
;
424 Withed
: out Boolean;
425 Exit_On_Self
: Boolean := False)
427 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
435 Cont_Item
:= First
(Context_List
);
436 while Present
(Cont_Item
) loop
438 -- Stop the search since the context items after Cont_Item have
439 -- already been examined in a previous iteration of the reverse
440 -- loop in Check_Redundant_Withs.
443 and Cont_Item
= Clause
448 -- Package use clause
450 if Nkind
(Cont_Item
) = N_Use_Package_Clause
453 Use_Item
:= First
(Names
(Cont_Item
));
454 while Present
(Use_Item
) and then not Used
loop
455 if Entity
(Use_Item
) = Nam_Ent
then
462 -- Package with clause. Avoid processing self, implicitly
463 -- generated with clauses or limited with clauses. Note that
464 -- we examine with clauses having pragmas Elaborate or
465 -- Elaborate_All applied to them due to cases such as:
469 -- pragma Elaborate (Pack);
471 -- In this case, the second with clause is redundant since
472 -- the pragma applies only to the first "with Pack;".
474 -- Note that we only consider with_clauses that comes from
475 -- source. In the case of renamings used as prefixes of names
476 -- in with_clauses, we generate a with_clause for the prefix,
477 -- which we do not treat as implicit because it is needed for
478 -- visibility analysis, but is also not redundant.
480 elsif Nkind
(Cont_Item
) = N_With_Clause
481 and then not Implicit_With
(Cont_Item
)
482 and then Comes_From_Source
(Cont_Item
)
483 and then not Limited_Present
(Cont_Item
)
484 and then Cont_Item
/= Clause
485 and then Entity
(Name
(Cont_Item
)) = Nam_Ent
492 end Process_Spec_Clauses
;
494 -- Start of processing for Check_Redundant_Withs
497 Clause
:= Last
(Context_Items
);
498 while Present
(Clause
) loop
500 -- Avoid checking implicitly generated with clauses, limited with
501 -- clauses or withs that have pragma Elaborate or Elaborate_All.
503 if Nkind
(Clause
) = N_With_Clause
504 and then not Implicit_With
(Clause
)
505 and then not Limited_Present
(Clause
)
506 and then not Elaborate_Present
(Clause
)
508 -- With_clauses introduced for renamings of parent clauses
509 -- are not marked implicit because they need to be properly
510 -- installed, but they do not come from source and do not
513 and then Comes_From_Source
(Clause
)
515 -- Package body-to-spec check
517 if Present
(Spec_Context_Items
) then
519 Used_In_Body
: Boolean;
520 Used_In_Spec
: Boolean;
521 Used_Type_Or_Elab
: Boolean;
522 Withed_In_Spec
: Boolean;
526 (Context_List
=> Spec_Context_Items
,
528 Used
=> Used_In_Spec
,
529 Withed
=> Withed_In_Spec
);
532 (Context_List
=> Context_Items
,
534 Used
=> Used_In_Body
,
535 Used_Type_Or_Elab
=> Used_Type_Or_Elab
);
537 -- "Type Elab" refers to the presence of either a use
538 -- type clause, pragmas Elaborate or Elaborate_All.
540 -- +---------------+---------------------------+------+
541 -- | Spec | Body | Warn |
542 -- +--------+------+--------+------+-----------+------+
543 -- | Withed | Used | Withed | Used | Type Elab | |
544 -- | X | | X | | | X |
545 -- | X | | X | X | | |
546 -- | X | | X | | X | |
547 -- | X | | X | X | X | |
548 -- | X | X | X | | | X |
549 -- | X | X | X | | X | |
550 -- | X | X | X | X | | X |
551 -- | X | X | X | X | X | |
552 -- +--------+------+--------+------+-----------+------+
555 and then not Used_Type_Or_Elab
)
557 ((not Used_In_Spec
and then not Used_In_Body
)
558 or else Used_In_Spec
)
560 Error_Msg_N
-- CODEFIX
561 ("redundant with clause in body?r?", Clause
);
564 Used_In_Body
:= False;
565 Used_In_Spec
:= False;
566 Used_Type_Or_Elab
:= False;
567 Withed_In_Spec
:= False;
570 -- Standalone package spec or body check
574 Dont_Care
: Boolean := False;
575 Withed
: Boolean := False;
578 -- The mechanism for examining the context clauses of a
579 -- package spec can be applied to package body clauses.
582 (Context_List
=> Context_Items
,
586 Exit_On_Self
=> True);
589 Error_Msg_N
-- CODEFIX
590 ("redundant with clause?r?", Clause
);
598 end Check_Redundant_Withs
;
602 Main_Cunit
: constant Node_Id
:= Cunit
(Main_Unit
);
603 Unit_Node
: constant Node_Id
:= Unit
(N
);
604 Lib_Unit
: Node_Id
:= Library_Unit
(N
);
605 Par_Spec_Name
: Unit_Name_Type
;
607 Unum
: Unit_Number_Type
;
609 -- Start of processing for Analyze_Compilation_Unit
612 Process_Compilation_Unit_Pragmas
(N
);
614 -- If the unit is a subunit whose parent has not been analyzed (which
615 -- indicates that the main unit is a subunit, either the current one or
616 -- one of its descendants) then the subunit is compiled as part of the
617 -- analysis of the parent, which we proceed to do. Basically this gets
618 -- handled from the top down and we don't want to do anything at this
619 -- level (i.e. this subunit will be handled on the way down from the
620 -- parent), so at this level we immediately return. If the subunit ends
621 -- up not analyzed, it means that the parent did not contain a stub for
622 -- it, or that there errors were detected in some ancestor.
624 if Nkind
(Unit_Node
) = N_Subunit
and then not Analyzed
(Lib_Unit
) then
625 Semantics
(Lib_Unit
);
627 if not Analyzed
(Proper_Body
(Unit_Node
)) then
628 if Serious_Errors_Detected
> 0 then
629 Error_Msg_N
("subunit not analyzed (errors in parent unit)", N
);
631 Error_Msg_N
("missing stub for subunit", N
);
638 -- Analyze context (this will call Sem recursively for with'ed units) To
639 -- detect circularities among with-clauses that are not caught during
640 -- loading, we set the Context_Pending flag on the current unit. If the
641 -- flag is already set there is a potential circularity. We exclude
642 -- predefined units from this check because they are known to be safe.
643 -- We also exclude package bodies that are present because circularities
644 -- between bodies are harmless (and necessary).
646 if Context_Pending
(N
) then
648 Circularity
: Boolean := True;
651 if In_Predefined_Unit
(N
) then
652 Circularity
:= False;
655 for U
in Main_Unit
+ 1 .. Last_Unit
loop
656 if Nkind
(Unit
(Cunit
(U
))) = N_Package_Body
657 and then not Analyzed
(Cunit
(U
))
659 Circularity
:= False;
666 Error_Msg_N
("circular dependency caused by with_clauses", N
);
668 ("\possibly missing limited_with clause"
669 & " in one of the following", N
);
671 for U
in Main_Unit
.. Last_Unit
loop
672 if Context_Pending
(Cunit
(U
)) then
673 Error_Msg_Unit_1
:= Get_Unit_Name
(Unit
(Cunit
(U
)));
674 Error_Msg_N
("\unit$", N
);
678 raise Unrecoverable_Error
;
682 Set_Context_Pending
(N
);
687 Set_Context_Pending
(N
, False);
689 -- If the unit is a package body, the spec is already loaded and must be
690 -- analyzed first, before we analyze the body.
692 if Nkind
(Unit_Node
) = N_Package_Body
then
694 -- If no Lib_Unit, then there was a serious previous error, so just
695 -- ignore the entire analysis effort.
697 if No
(Lib_Unit
) then
698 Check_Error_Detected
;
702 -- Analyze the package spec
704 Semantics
(Lib_Unit
);
706 -- Check for unused with's
708 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
710 -- Verify that the library unit is a package declaration
712 if not Nkind_In
(Unit
(Lib_Unit
), N_Package_Declaration
,
713 N_Generic_Package_Declaration
)
716 ("no legal package declaration for package body", N
);
719 -- Otherwise, the entity in the declaration is visible. Update the
720 -- version to reflect dependence of this body on the spec.
723 Spec_Id
:= Defining_Entity
(Unit
(Lib_Unit
));
724 Set_Is_Immediately_Visible
(Spec_Id
, True);
725 Version_Update
(N
, Lib_Unit
);
727 if Nkind
(Defining_Unit_Name
(Unit_Node
)) =
728 N_Defining_Program_Unit_Name
730 Generate_Parent_References
(Unit_Node
, Scope
(Spec_Id
));
735 -- If the unit is a subprogram body, then we similarly need to analyze
736 -- its spec. However, things are a little simpler in this case, because
737 -- here, this analysis is done mostly for error checking and consistency
738 -- purposes (but not only, e.g. there could be a contract on the spec),
739 -- so there's nothing else to be done.
741 elsif Nkind
(Unit_Node
) = N_Subprogram_Body
then
742 if Acts_As_Spec
(N
) then
744 -- If the subprogram body is a child unit, we must create a
745 -- declaration for it, in order to properly load the parent(s).
746 -- After this, the original unit does not acts as a spec, because
747 -- there is an explicit one. If this unit appears in a context
748 -- clause, then an implicit with on the parent will be added when
749 -- installing the context. If this is the main unit, there is no
750 -- Unit_Table entry for the declaration (it has the unit number
751 -- of the main unit) and code generation is unaffected.
753 Unum
:= Get_Cunit_Unit_Number
(N
);
754 Par_Spec_Name
:= Get_Parent_Spec_Name
(Unit_Name
(Unum
));
756 if Par_Spec_Name
/= No_Unit_Name
then
759 (Load_Name
=> Par_Spec_Name
,
764 if Unum
/= No_Unit
then
766 -- Build subprogram declaration and attach parent unit to it
767 -- This subprogram declaration does not come from source,
768 -- Nevertheless the backend must generate debugging info for
769 -- it, and this must be indicated explicitly. We also mark
770 -- the body entity as a child unit now, to prevent a
771 -- cascaded error if the spec entity cannot be entered
772 -- in its scope. Finally we create a Units table entry for
773 -- the subprogram declaration, to maintain a one-to-one
774 -- correspondence with compilation unit nodes. This is
775 -- critical for the tree traversals performed by CodePeer.
778 Loc
: constant Source_Ptr
:= Sloc
(N
);
779 SCS
: constant Boolean :=
780 Get_Comes_From_Source_Default
;
783 Set_Comes_From_Source_Default
(False);
785 -- Note: We copy the Context_Items from the explicit body
786 -- to the implicit spec, setting the former to Empty_List
787 -- to preserve the treeish nature of the tree, during
788 -- analysis of the spec. Then we put it back the way it
789 -- was -- copy the Context_Items from the spec to the
790 -- body, and set the spec Context_Items to Empty_List.
791 -- It is necessary to preserve the treeish nature,
792 -- because otherwise we will call End_Use_* twice on the
796 Make_Compilation_Unit
(Loc
,
797 Context_Items
=> Context_Items
(N
),
799 Make_Subprogram_Declaration
(Sloc
(N
),
802 (Specification
(Unit_Node
))),
804 Make_Compilation_Unit_Aux
(Loc
));
806 Set_Context_Items
(N
, Empty_List
);
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
);
820 -- Restore Context_Items to the body
822 Set_Context_Items
(N
, Context_Items
(Lib_Unit
));
823 Set_Context_Items
(Lib_Unit
, Empty_List
);
828 -- Here for subprogram with separate declaration
831 Semantics
(Lib_Unit
);
832 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
833 Version_Update
(N
, Lib_Unit
);
836 -- If this is a child unit, generate references to the parents
838 if Nkind
(Defining_Unit_Name
(Specification
(Unit_Node
))) =
839 N_Defining_Program_Unit_Name
841 Generate_Parent_References
842 (Specification
(Unit_Node
),
843 Scope
(Defining_Entity
(Unit
(Lib_Unit
))));
847 -- If it is a child unit, the parent must be elaborated first and we
848 -- update version, since we are dependent on our parent.
850 if Is_Child_Spec
(Unit_Node
) then
852 -- The analysis of the parent is done with style checks off
855 Save_Style_Check
: constant Boolean := Style_Check
;
858 if not GNAT_Mode
then
859 Style_Check
:= False;
862 Semantics
(Parent_Spec
(Unit_Node
));
863 Version_Update
(N
, Parent_Spec
(Unit_Node
));
865 -- Restore style check settings
867 Style_Check
:= Save_Style_Check
;
871 -- With the analysis done, install the context. Note that we can't
872 -- install the context from the with clauses as we analyze them, because
873 -- each with clause must be analyzed in a clean visibility context, so
874 -- we have to wait and install them all at once.
878 if Is_Child_Spec
(Unit_Node
) then
880 -- Set the entities of all parents in the program_unit_name
882 Generate_Parent_References
883 (Unit_Node
, Get_Parent_Entity
(Unit
(Parent_Spec
(Unit_Node
))));
886 -- All components of the context: with-clauses, library unit, ancestors
887 -- if any, (and their context) are analyzed and installed.
889 -- Call special debug routine sm if this is the main unit
891 if Current_Sem_Unit
= Main_Unit
then
895 -- Now analyze the unit (package, subprogram spec, body) itself
899 if Warn_On_Redundant_Constructs
then
900 Check_Redundant_Withs
(Context_Items
(N
));
902 if Nkind
(Unit_Node
) = N_Package_Body
then
903 Check_Redundant_Withs
904 (Context_Items
=> Context_Items
(N
),
905 Spec_Context_Items
=> Context_Items
(Lib_Unit
));
909 -- The above call might have made Unit_Node an N_Subprogram_Body from
910 -- something else, so propagate any Acts_As_Spec flag.
912 if Nkind
(Unit_Node
) = N_Subprogram_Body
913 and then Acts_As_Spec
(Unit_Node
)
915 Set_Acts_As_Spec
(N
);
918 -- Register predefined units in Rtsfind
920 if In_Predefined_Unit
(N
) then
921 Set_RTU_Loaded
(Unit_Node
);
924 -- Treat compilation unit pragmas that appear after the library unit
926 if Present
(Pragmas_After
(Aux_Decls_Node
(N
))) then
928 Prag_Node
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(N
)));
930 while Present
(Prag_Node
) loop
937 -- Analyze the contract of a [generic] subprogram that acts as a
938 -- compilation unit after all compilation pragmas have been analyzed.
940 if Nkind_In
(Unit_Node
, N_Generic_Subprogram_Declaration
,
941 N_Subprogram_Declaration
)
943 Analyze_Entry_Or_Subprogram_Contract
(Defining_Entity
(Unit_Node
));
946 -- Generate distribution stubs if requested and no error
949 and then (Distribution_Stub_Mode
= Generate_Receiver_Stub_Body
951 Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
952 and then Fatal_Error
(Main_Unit
) /= Error_Detected
954 if Is_RCI_Pkg_Spec_Or_Body
(N
) then
956 -- Regular RCI package
958 Add_Stub_Constructs
(N
);
960 elsif (Nkind
(Unit_Node
) = N_Package_Declaration
961 and then Is_Shared_Passive
(Defining_Entity
962 (Specification
(Unit_Node
))))
963 or else (Nkind
(Unit_Node
) = N_Package_Body
965 Is_Shared_Passive
(Corresponding_Spec
(Unit_Node
)))
967 -- Shared passive package
969 Add_Stub_Constructs
(N
);
971 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
973 Is_Remote_Call_Interface
974 (Defining_Entity
(Specification
(Instance_Spec
(Unit_Node
))))
976 -- Instantiation of a RCI generic package
978 Add_Stub_Constructs
(N
);
982 -- Remove unit from visibility, so that environment is clean for the
983 -- next compilation, which is either the main unit or some other unit
986 if Nkind_In
(Unit_Node
, N_Package_Declaration
,
987 N_Package_Renaming_Declaration
,
988 N_Subprogram_Declaration
)
989 or else Nkind
(Unit_Node
) in N_Generic_Declaration
990 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
991 and then Acts_As_Spec
(Unit_Node
))
993 Remove_Unit_From_Visibility
(Defining_Entity
(Unit_Node
));
995 -- If the unit is an instantiation whose body will be elaborated for
996 -- inlining purposes, use the proper entity of the instance. The entity
997 -- may be missing if the instantiation was illegal.
999 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
1000 and then not Error_Posted
(Unit_Node
)
1001 and then Present
(Instance_Spec
(Unit_Node
))
1003 Remove_Unit_From_Visibility
1004 (Defining_Entity
(Instance_Spec
(Unit_Node
)));
1006 elsif Nkind
(Unit_Node
) = N_Package_Body
1007 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
1008 and then not Acts_As_Spec
(Unit_Node
))
1010 -- Bodies that are not the main unit are compiled if they are generic
1011 -- or contain generic or inlined units. Their analysis brings in the
1012 -- context of the corresponding spec (unit declaration) which must be
1013 -- removed as well, to return the compilation environment to its
1016 Remove_Context
(Lib_Unit
);
1017 Set_Is_Immediately_Visible
(Defining_Entity
(Unit
(Lib_Unit
)), False);
1020 -- Last step is to deinstall the context we just installed as well as
1021 -- the unit just compiled.
1025 -- When generating code for a non-generic main unit, check that withed
1026 -- generic units have a body if they need it, even if the units have not
1027 -- been instantiated. Force the load of the bodies to produce the proper
1028 -- error if the body is absent. The same applies to GNATprove mode, with
1029 -- the added benefit of capturing global references within the generic.
1030 -- This in turn allows for proper inlining of subprogram bodies without
1031 -- a previous declaration.
1033 if Get_Cunit_Unit_Number
(N
) = Main_Unit
1034 and then ((Operating_Mode
= Generate_Code
and then Expander_Active
)
1036 (Operating_Mode
= Check_Semantics
and then GNATprove_Mode
))
1038 -- Check whether the source for the body of the unit must be included
1039 -- in a standalone library.
1041 Check_Body_Needed_For_SAL
(Cunit_Entity
(Main_Unit
));
1043 -- Indicate that the main unit is now analyzed, to catch possible
1044 -- circularities between it and generic bodies. Remove main unit from
1045 -- visibility. This might seem superfluous, but the main unit must
1046 -- not be visible in the generic body expansions that follow.
1048 Set_Analyzed
(N
, True);
1049 Set_Is_Immediately_Visible
(Cunit_Entity
(Main_Unit
), False);
1054 Un
: Unit_Number_Type
;
1056 Save_Style_Check
: constant Boolean := Style_Check
;
1059 Item
:= First
(Context_Items
(N
));
1060 while Present
(Item
) loop
1062 -- Check for explicit with clause
1064 if Nkind
(Item
) = N_With_Clause
1065 and then not Implicit_With
(Item
)
1067 -- Ada 2005 (AI-50217): Ignore limited-withed units
1069 and then not Limited_Present
(Item
)
1071 Nam
:= Entity
(Name
(Item
));
1073 -- Compile the generic subprogram, unless it is intrinsic or
1074 -- imported so no body is required, or generic package body
1075 -- if the package spec requires a body.
1077 if (Is_Generic_Subprogram
(Nam
)
1078 and then not Is_Intrinsic_Subprogram
(Nam
)
1079 and then not Is_Imported
(Nam
))
1080 or else (Ekind
(Nam
) = E_Generic_Package
1081 and then Unit_Requires_Body
(Nam
))
1083 Style_Check
:= False;
1085 if Present
(Renamed_Object
(Nam
)) then
1091 (Unit_Declaration_Node
1092 (Renamed_Object
(Nam
)))),
1101 Get_Body_Name
(Get_Unit_Name
(Item
)),
1108 if Un
= No_Unit
then
1110 ("body of generic unit& not found", Item
, Nam
);
1113 elsif not Analyzed
(Cunit
(Un
))
1114 and then Un
/= Main_Unit
1115 and then Fatal_Error
(Un
) /= Error_Detected
1117 Style_Check
:= False;
1118 Semantics
(Cunit
(Un
));
1126 -- Restore style checks settings
1128 Style_Check
:= Save_Style_Check
;
1131 -- In GNATprove mode, force the loading of an Interrupt_Priority when
1132 -- processing compilation units with potentially "main" subprograms.
1133 -- This is required for the ceiling priority protocol checks, which
1134 -- are triggered by these subprograms.
1137 and then Nkind_In
(Unit_Node
, N_Function_Instantiation
,
1138 N_Procedure_Instantiation
,
1145 case Nkind
(Unit_Node
) is
1146 when N_Subprogram_Body
=>
1147 Spec
:= Specification
(Unit_Node
);
1149 when N_Subprogram_Instantiation
=>
1151 Subprogram_Specification
(Entity
(Name
(Unit_Node
)));
1154 raise Program_Error
;
1157 pragma Assert
(Nkind
(Spec
) in N_Subprogram_Specification
);
1159 -- Main subprogram must have no parameters, and if it is a
1160 -- function, it must return an integer.
1162 if No
(Parameter_Specifications
(Spec
))
1163 and then (Nkind
(Spec
) = N_Procedure_Specification
1165 Is_Integer_Type
(Etype
(Result_Definition
(Spec
))))
1167 SPARK_Implicit_Load
(RE_Interrupt_Priority
);
1173 -- Deal with creating elaboration counter if needed. We create an
1174 -- elaboration counter only for units that come from source since
1175 -- units manufactured by the compiler never need elab checks.
1177 if Comes_From_Source
(N
)
1178 and then Nkind_In
(Unit_Node
, N_Package_Declaration
,
1179 N_Generic_Package_Declaration
,
1180 N_Subprogram_Declaration
,
1181 N_Generic_Subprogram_Declaration
)
1184 Loc
: constant Source_Ptr
:= Sloc
(N
);
1185 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
1188 Spec_Id
:= Defining_Entity
(Unit_Node
);
1189 Generate_Definition
(Spec_Id
);
1191 -- See if an elaboration entity is required for possible access
1192 -- before elaboration checking. Note that we must allow for this
1193 -- even if -gnatE is not set, since a client may be compiled in
1194 -- -gnatE mode and reference the entity.
1196 -- These entities are also used by the binder to prevent multiple
1197 -- attempts to execute the elaboration code for the library case
1198 -- where the elaboration routine might otherwise be called more
1201 -- They are also needed to ensure explicit visibility from the
1202 -- binder generated code of all the units involved in a partition
1203 -- when control-flow preservation is requested.
1205 -- Case of units which do not require an elaboration entity
1207 if not Opt
.Suppress_Control_Flow_Optimizations
1209 ( -- Pure units do not need checks
1213 -- Preelaborated units do not need checks
1215 or else Is_Preelaborated
(Spec_Id
)
1217 -- No checks needed if pragma Elaborate_Body present
1219 or else Has_Pragma_Elaborate_Body
(Spec_Id
)
1221 -- No checks needed if unit does not require a body
1223 or else not Unit_Requires_Body
(Spec_Id
)
1225 -- No checks needed for predefined files
1227 or else Is_Predefined_Unit
(Unum
)
1229 -- No checks required if no separate spec
1231 or else Acts_As_Spec
(N
)
1234 -- This is a case where we only need the entity for
1235 -- checking to prevent multiple elaboration checks.
1237 Set_Elaboration_Entity_Required
(Spec_Id
, False);
1239 -- Case of elaboration entity is required for access before
1240 -- elaboration checking (so certainly we must build it).
1243 Set_Elaboration_Entity_Required
(Spec_Id
, True);
1246 Build_Elaboration_Entity
(N
, Spec_Id
);
1250 -- Freeze the compilation unit entity. This for sure is needed because
1251 -- of some warnings that can be output (see Freeze_Subprogram), but may
1252 -- in general be required. If freezing actions result, place them in the
1253 -- compilation unit actions list, and analyze them.
1256 L
: constant List_Id
:=
1257 Freeze_Entity
(Cunit_Entity
(Current_Sem_Unit
), N
);
1259 while Is_Non_Empty_List
(L
) loop
1260 Insert_Library_Level_Action
(Remove_Head
(L
));
1266 -- Call Check_Package_Body so that a body containing subprograms with
1267 -- Inline_Always can be made available for front end inlining.
1269 if Nkind
(Unit_Node
) = N_Package_Declaration
1270 and then Get_Cunit_Unit_Number
(N
) /= Main_Unit
1272 -- We don't need to do this if the Expander is not active, since there
1273 -- is no code to inline.
1275 and then Expander_Active
1278 Save_Style_Check
: constant Boolean := Style_Check
;
1279 Save_Warning
: constant Warning_Mode_Type
:= Warning_Mode
;
1280 Options
: Style_Check_Options
;
1283 Save_Style_Check_Options
(Options
);
1284 Reset_Style_Check_Options
;
1285 Opt
.Warning_Mode
:= Suppress
;
1287 Check_Package_Body_For_Inlining
(N
, Defining_Entity
(Unit_Node
));
1289 Reset_Style_Check_Options
;
1290 Set_Style_Check_Options
(Options
);
1291 Style_Check
:= Save_Style_Check
;
1292 Warning_Mode
:= Save_Warning
;
1296 -- If we are generating obsolescent warnings, then here is where we
1297 -- generate them for the with'ed items. The reason for this special
1298 -- processing is that the normal mechanism of generating the warnings
1299 -- for referenced entities does not work for context clause references.
1300 -- That's because when we first analyze the context, it is too early to
1301 -- know if the with'ing unit is itself obsolescent (which suppresses
1305 and then Warn_On_Obsolescent_Feature
1306 and then Nkind
(Unit_Node
) not in N_Generic_Instantiation
1308 -- Push current compilation unit as scope, so that the test for
1309 -- being within an obsolescent unit will work correctly. The check
1310 -- is not performed within an instantiation, because the warning
1311 -- will have been emitted in the corresponding generic unit.
1313 Push_Scope
(Defining_Entity
(Unit_Node
));
1315 -- Loop through context items to deal with with clauses
1323 Item
:= First
(Context_Items
(N
));
1324 while Present
(Item
) loop
1325 if Nkind
(Item
) = N_With_Clause
1327 -- Suppress this check in limited-withed units. Further work
1328 -- needed here if we decide to incorporate this check on
1329 -- limited-withed units.
1331 and then not Limited_Present
(Item
)
1334 Ent
:= Entity
(Nam
);
1336 if Is_Obsolescent
(Ent
) then
1337 Output_Obsolescent_Entity_Warnings
(Nam
, Ent
);
1345 -- Remove temporary install of current unit as scope
1350 -- If No_Elaboration_Code_All was encountered, this is where we do the
1351 -- transitive test of with'ed units to make sure they have the aspect.
1352 -- This is delayed till the end of analyzing the compilation unit to
1353 -- ensure that the pragma/aspect, if present, has been analyzed.
1355 Check_No_Elab_Code_All
(N
);
1356 end Analyze_Compilation_Unit
;
1358 ---------------------
1359 -- Analyze_Context --
1360 ---------------------
1362 procedure Analyze_Context
(N
: Node_Id
) is
1363 Ukind
: constant Node_Kind
:= Nkind
(Unit
(N
));
1367 -- First process all configuration pragmas at the start of the context
1368 -- items. Strictly these are not part of the context clause, but that
1369 -- is where the parser puts them. In any case for sure we must analyze
1370 -- these before analyzing the actual context items, since they can have
1371 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1372 -- be with'ed as a result of changing categorizations in Ada 2005).
1374 Item
:= First
(Context_Items
(N
));
1375 while Present
(Item
)
1376 and then Nkind
(Item
) = N_Pragma
1377 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
1383 -- This is the point at which we capture the configuration settings
1384 -- for the unit. At the moment only the Optimize_Alignment setting
1385 -- needs to be captured. Probably more later ???
1387 if Optimize_Alignment_Local
then
1388 Set_OA_Setting
(Current_Sem_Unit
, 'L');
1390 Set_OA_Setting
(Current_Sem_Unit
, Optimize_Alignment
);
1393 -- Loop through actual context items. This is done in two passes:
1395 -- a) The first pass analyzes non-limited with-clauses and also any
1396 -- configuration pragmas (we need to get the latter analyzed right
1397 -- away, since they can affect processing of subsequent items).
1399 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1401 while Present
(Item
) loop
1403 -- For with clause, analyze the with clause, and then update the
1404 -- version, since we are dependent on a unit that we with.
1406 if Nkind
(Item
) = N_With_Clause
1407 and then not Limited_Present
(Item
)
1409 -- Skip analyzing with clause if no unit, nothing to do (this
1410 -- happens for a with that references a non-existent unit).
1412 if Present
(Library_Unit
(Item
)) then
1414 -- Skip analyzing with clause if this is a with_clause for
1415 -- the main unit, which happens if a subunit has a useless
1416 -- with_clause on its parent.
1418 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
) then
1421 -- Here for the case of a useless with for the main unit
1424 Set_Entity
(Name
(Item
), Cunit_Entity
(Current_Sem_Unit
));
1428 -- Do version update (skipped for implicit with)
1430 if not Implicit_With
(Item
) then
1431 Version_Update
(N
, Library_Unit
(Item
));
1434 -- Skip pragmas. Configuration pragmas at the start were handled in
1435 -- the loop above, and remaining pragmas are not processed until we
1436 -- actually install the context (see Install_Context). We delay the
1437 -- analysis of these pragmas to make sure that we have installed all
1438 -- the implicit with's on parent units.
1440 -- Skip use clauses at this stage, since we don't want to do any
1441 -- installing of potentially use-visible entities until we
1442 -- actually install the complete context (in Install_Context).
1443 -- Otherwise things can get installed in the wrong context.
1452 -- Second pass: examine all limited_with clauses. All other context
1453 -- items are ignored in this pass.
1455 Item
:= First
(Context_Items
(N
));
1456 while Present
(Item
) loop
1457 if Nkind
(Item
) = N_With_Clause
1458 and then Limited_Present
(Item
)
1460 -- No need to check errors on implicitly generated limited-with
1463 if not Implicit_With
(Item
) then
1465 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1466 -- properly rejected, including renaming declarations.
1468 if not Nkind_In
(Ukind
, N_Package_Declaration
,
1469 N_Subprogram_Declaration
)
1470 and then Ukind
not in N_Generic_Declaration
1471 and then Ukind
not in N_Generic_Instantiation
1473 Error_Msg_N
("limited with_clause not allowed here", Item
);
1475 -- Check wrong use of a limited with clause applied to the
1476 -- compilation unit containing the limited-with clause.
1478 -- limited with P.Q;
1479 -- package P.Q is ...
1481 elsif Unit
(Library_Unit
(Item
)) = Unit
(N
) then
1482 Error_Msg_N
("wrong use of limited-with clause", Item
);
1484 -- Check wrong use of limited-with clause applied to some
1485 -- immediate ancestor.
1487 elsif Is_Child_Spec
(Unit
(N
)) then
1489 Lib_U
: constant Entity_Id
:= Unit
(Library_Unit
(Item
));
1493 P
:= Parent_Spec
(Unit
(N
));
1495 if Unit
(P
) = Lib_U
then
1496 Error_Msg_N
("limited with_clause cannot "
1497 & "name ancestor", Item
);
1501 exit when not Is_Child_Spec
(Unit
(P
));
1502 P
:= Parent_Spec
(Unit
(P
));
1507 -- Check if the limited-withed unit is already visible through
1508 -- some context clause of the current compilation unit or some
1509 -- ancestor of the current compilation unit.
1512 Lim_Unit_Name
: constant Node_Id
:= Name
(Item
);
1513 Comp_Unit
: Node_Id
;
1515 Unit_Name
: Node_Id
;
1520 It
:= First
(Context_Items
(Comp_Unit
));
1521 while Present
(It
) loop
1523 and then Nkind
(It
) = N_With_Clause
1524 and then not Limited_Present
(It
)
1526 Nkind_In
(Unit
(Library_Unit
(It
)),
1527 N_Package_Declaration
,
1528 N_Package_Renaming_Declaration
)
1530 if Nkind
(Unit
(Library_Unit
(It
))) =
1531 N_Package_Declaration
1533 Unit_Name
:= Name
(It
);
1535 Unit_Name
:= Name
(Unit
(Library_Unit
(It
)));
1538 -- Check if the named package (or some ancestor)
1539 -- leaves visible the full-view of the unit given
1540 -- in the limited-with clause.
1543 if Designate_Same_Unit
(Lim_Unit_Name
,
1546 Error_Msg_Sloc
:= Sloc
(It
);
1548 ("simultaneous visibility of limited "
1549 & "and unlimited views not allowed",
1552 ("\unlimited view visible through "
1553 & "context clause #",
1557 elsif Nkind
(Unit_Name
) = N_Identifier
then
1561 Unit_Name
:= Prefix
(Unit_Name
);
1568 exit when not Is_Child_Spec
(Unit
(Comp_Unit
));
1570 Comp_Unit
:= Parent_Spec
(Unit
(Comp_Unit
));
1575 -- Skip analyzing with clause if no unit, see above
1577 if Present
(Library_Unit
(Item
)) then
1581 -- A limited_with does not impose an elaboration order, but
1582 -- there is a semantic dependency for recompilation purposes.
1584 if not Implicit_With
(Item
) then
1585 Version_Update
(N
, Library_Unit
(Item
));
1588 -- Pragmas and use clauses and with clauses other than limited
1589 -- with's are ignored in this pass through the context items.
1597 end Analyze_Context
;
1599 -------------------------------
1600 -- Analyze_Package_Body_Stub --
1601 -------------------------------
1603 procedure Analyze_Package_Body_Stub
(N
: Node_Id
) is
1604 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1606 Opts
: Config_Switches_Type
;
1609 -- The package declaration must be in the current declarative part
1611 Check_Stub_Level
(N
);
1612 Nam
:= Current_Entity_In_Scope
(Id
);
1614 if No
(Nam
) or else not Is_Package_Or_Generic_Package
(Nam
) then
1615 Error_Msg_N
("missing specification for package stub", N
);
1617 elsif Has_Completion
(Nam
)
1618 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(Nam
)))
1620 Error_Msg_N
("duplicate or redundant stub for package", N
);
1623 -- Retain and restore the configuration options of the enclosing
1624 -- context as the proper body may introduce a set of its own.
1626 Save_Opt_Config_Switches
(Opts
);
1628 -- Indicate that the body of the package exists. If we are doing
1629 -- only semantic analysis, the stub stands for the body. If we are
1630 -- generating code, the existence of the body will be confirmed
1631 -- when we load the proper body.
1633 Set_Has_Completion
(Nam
);
1634 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1635 Set_Ekind
(Defining_Entity
(N
), E_Package_Body
);
1636 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1637 Generate_Reference
(Nam
, Id
, 'b');
1638 Analyze_Proper_Body
(N
, Nam
);
1640 Restore_Opt_Config_Switches
(Opts
);
1642 end Analyze_Package_Body_Stub
;
1644 -------------------------
1645 -- Analyze_Proper_Body --
1646 -------------------------
1648 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
) is
1649 Subunit_Name
: constant Unit_Name_Type
:= Get_Unit_Name
(N
);
1651 procedure Optional_Subunit
;
1652 -- This procedure is called when the main unit is a stub, or when we
1653 -- are not generating code. In such a case, we analyze the subunit if
1654 -- present, which is user-friendly and in fact required for ASIS, but we
1655 -- don't complain if the subunit is missing. In GNATprove_Mode, we issue
1656 -- an error to avoid formal verification of a partial unit.
1658 ----------------------
1659 -- Optional_Subunit --
1660 ----------------------
1662 procedure Optional_Subunit
is
1663 Comp_Unit
: Node_Id
;
1664 Unum
: Unit_Number_Type
;
1667 -- Try to load subunit, but ignore any errors that occur during the
1668 -- loading of the subunit, by using the special feature in Errout to
1669 -- ignore all errors. Note that Fatal_Error will still be set, so we
1670 -- will be able to check for this case below.
1672 if not (ASIS_Mode
or GNATprove_Mode
) then
1673 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
1678 (Load_Name
=> Subunit_Name
,
1679 Required
=> GNATprove_Mode
,
1683 if not (ASIS_Mode
or GNATprove_Mode
) then
1684 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
1687 -- All done if we successfully loaded the subunit
1690 and then (Fatal_Error
(Unum
) /= Error_Detected
1691 or else Try_Semantics
)
1693 Comp_Unit
:= Cunit
(Unum
);
1695 -- If the file was empty or seriously mangled, the unit itself may
1698 if No
(Unit
(Comp_Unit
)) then
1700 ("subunit does not contain expected proper body", N
);
1702 elsif Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1704 ("expected SEPARATE subunit, found child unit",
1705 Cunit_Entity
(Unum
));
1707 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1708 Analyze_Subunit
(Comp_Unit
);
1709 Set_Library_Unit
(N
, Comp_Unit
);
1710 Set_Corresponding_Body
(N
, Defining_Entity
(Unit
(Comp_Unit
)));
1713 elsif Unum
= No_Unit
1714 and then Present
(Nam
)
1716 if Is_Protected_Type
(Nam
) then
1717 Set_Corresponding_Body
(Parent
(Nam
), Defining_Identifier
(N
));
1719 Set_Corresponding_Body
(
1720 Unit_Declaration_Node
(Nam
), Defining_Identifier
(N
));
1723 end Optional_Subunit
;
1727 Comp_Unit
: Node_Id
;
1728 Unum
: Unit_Number_Type
;
1730 -- Start of processing for Analyze_Proper_Body
1733 -- If the subunit is already loaded, it means that the main unit is a
1734 -- subunit, and that the current unit is one of its parents which was
1735 -- being analyzed to provide the needed context for the analysis of the
1736 -- subunit. In this case we analyze the subunit and continue with the
1737 -- parent, without looking at subsequent subunits.
1739 if Is_Loaded
(Subunit_Name
) then
1741 -- If the proper body is already linked to the stub node, the stub is
1742 -- in a generic unit and just needs analyzing.
1744 if Present
(Library_Unit
(N
)) then
1745 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1747 -- If the subunit has severe errors, the spec of the enclosing
1748 -- body may not be available, in which case do not try analysis.
1750 if Serious_Errors_Detected
> 0
1751 and then No
(Library_Unit
(Library_Unit
(N
)))
1756 -- Collect SCO information for loaded subunit if we are in the
1757 -- extended main unit.
1760 and then In_Extended_Main_Source_Unit
1761 (Cunit_Entity
(Current_Sem_Unit
))
1763 SCO_Record_Raw
(Get_Cunit_Unit_Number
(Library_Unit
(N
)));
1766 Analyze_Subunit
(Library_Unit
(N
));
1768 -- Otherwise we must load the subunit and link to it
1771 -- Load the subunit, this must work, since we originally loaded
1772 -- the subunit earlier on. So this will not really load it, just
1773 -- give access to it.
1777 (Load_Name
=> Subunit_Name
,
1782 -- And analyze the subunit in the parent context (note that we
1783 -- do not call Semantics, since that would remove the parent
1784 -- context). Because of this, we have to manually reset the
1785 -- compiler state to Analyzing since it got destroyed by Load.
1787 if Unum
/= No_Unit
then
1788 Compiler_State
:= Analyzing
;
1790 -- Check that the proper body is a subunit and not a child
1791 -- unit. If the unit was previously loaded, the error will
1792 -- have been emitted when copying the generic node, so we
1793 -- just return to avoid cascaded errors.
1795 if Nkind
(Unit
(Cunit
(Unum
))) /= N_Subunit
then
1799 Set_Corresponding_Stub
(Unit
(Cunit
(Unum
)), N
);
1800 Analyze_Subunit
(Cunit
(Unum
));
1801 Set_Library_Unit
(N
, Cunit
(Unum
));
1805 -- If the main unit is a subunit, then we are just performing semantic
1806 -- analysis on that subunit, and any other subunits of any parent unit
1807 -- should be ignored, except that if we are building trees for ASIS
1808 -- usage we want to annotate the stub properly. If the main unit is
1809 -- itself a subunit, another subunit is irrelevant unless it is a
1810 -- subunit of the current one, that is to say appears in the current
1813 elsif Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
1814 and then Subunit_Name
/= Unit_Name
(Main_Unit
)
1818 PB
: constant Node_Id
:= Proper_Body
(Unit
(Cunit
(Main_Unit
)));
1820 if Nkind_In
(PB
, N_Package_Body
, N_Subprogram_Body
)
1821 and then List_Containing
(N
) = Declarations
(PB
)
1828 -- But before we return, set the flag for unloaded subunits. This
1829 -- will suppress junk warnings of variables in the same declarative
1830 -- part (or a higher level one) that are in danger of looking unused
1831 -- when in fact there might be a declaration in the subunit that we
1832 -- do not intend to load.
1834 Unloaded_Subunits
:= True;
1837 -- If the subunit is not already loaded, and we are generating code,
1838 -- then this is the case where compilation started from the parent, and
1839 -- we are generating code for an entire subunit tree. In that case we
1840 -- definitely need to load the subunit.
1842 -- In order to continue the analysis with the rest of the parent,
1843 -- and other subunits, we load the unit without requiring its
1844 -- presence, and emit a warning if not found, rather than terminating
1845 -- the compilation abruptly, as for other missing file problems.
1847 elsif Original_Operating_Mode
= Generate_Code
then
1849 -- If the proper body is already linked to the stub node, the stub is
1850 -- in a generic unit and just needs analyzing.
1852 -- We update the version. Although we are not strictly technically
1853 -- semantically dependent on the subunit, given our approach of macro
1854 -- substitution of subunits, it makes sense to include it in the
1855 -- version identification.
1857 if Present
(Library_Unit
(N
)) then
1858 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1859 Analyze_Subunit
(Library_Unit
(N
));
1860 Version_Update
(Cunit
(Main_Unit
), Library_Unit
(N
));
1862 -- Otherwise we must load the subunit and link to it
1865 -- Make sure that, if the subunit is preprocessed and -gnateG is
1866 -- specified, the preprocessed file will be written.
1868 Lib
.Analysing_Subunit_Of_Main
:= True;
1871 (Load_Name
=> Subunit_Name
,
1875 Lib
.Analysing_Subunit_Of_Main
:= False;
1877 -- Give message if we did not get the unit Emit warning even if
1878 -- missing subunit is not within main unit, to simplify debugging.
1880 pragma Assert
(Original_Operating_Mode
= Generate_Code
);
1881 if Unum
= No_Unit
then
1882 Error_Msg_Unit_1
:= Subunit_Name
;
1884 Get_File_Name
(Subunit_Name
, Subunit
=> True);
1886 ("subunit$$ in file{ not found??!!", N
);
1887 Subunits_Missing
:= True;
1890 -- Load_Unit may reset Compiler_State, since it may have been
1891 -- necessary to parse an additional units, so we make sure that
1892 -- we reset it to the Analyzing state.
1894 Compiler_State
:= Analyzing
;
1896 if Unum
/= No_Unit
then
1897 if Debug_Flag_L
then
1898 Write_Str
("*** Loaded subunit from stub. Analyze");
1902 Comp_Unit
:= Cunit
(Unum
);
1904 -- Check for child unit instead of subunit
1906 if Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1908 ("expected SEPARATE subunit, found child unit",
1909 Cunit_Entity
(Unum
));
1911 -- OK, we have a subunit
1914 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1915 Set_Library_Unit
(N
, Comp_Unit
);
1917 -- We update the version. Although we are not technically
1918 -- semantically dependent on the subunit, given our approach
1919 -- of macro substitution of subunits, it makes sense to
1920 -- include it in the version identification.
1922 Version_Update
(Cunit
(Main_Unit
), Comp_Unit
);
1924 -- Collect SCO information for loaded subunit if we are in
1925 -- the extended main unit.
1928 and then In_Extended_Main_Source_Unit
1929 (Cunit_Entity
(Current_Sem_Unit
))
1931 SCO_Record_Raw
(Unum
);
1934 -- Analyze the unit if semantics active
1936 if Fatal_Error
(Unum
) /= Error_Detected
1937 or else Try_Semantics
1939 Analyze_Subunit
(Comp_Unit
);
1945 -- The remaining case is when the subunit is not already loaded and we
1946 -- are not generating code. In this case we are just performing semantic
1947 -- analysis on the parent, and we are not interested in the subunit. For
1948 -- subprograms, analyze the stub as a body. For other entities the stub
1949 -- has already been marked as completed.
1954 end Analyze_Proper_Body
;
1956 ----------------------------------
1957 -- Analyze_Protected_Body_Stub --
1958 ----------------------------------
1960 procedure Analyze_Protected_Body_Stub
(N
: Node_Id
) is
1961 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
1964 Check_Stub_Level
(N
);
1966 -- First occurrence of name may have been as an incomplete type
1968 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
1969 Nam
:= Full_View
(Nam
);
1972 if No
(Nam
) or else not Is_Protected_Type
(Etype
(Nam
)) then
1973 Error_Msg_N
("missing specification for Protected body", N
);
1976 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1977 Set_Ekind
(Defining_Entity
(N
), E_Protected_Body
);
1978 Set_Has_Completion
(Etype
(Nam
));
1979 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1980 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
1981 Analyze_Proper_Body
(N
, Etype
(Nam
));
1983 end Analyze_Protected_Body_Stub
;
1985 ----------------------------------
1986 -- Analyze_Subprogram_Body_Stub --
1987 ----------------------------------
1989 -- A subprogram body stub can appear with or without a previous spec. If
1990 -- there is one, then the analysis of the body will find it and verify
1991 -- conformance. The formals appearing in the specification of the stub play
1992 -- no role, except for requiring an additional conformance check. If there
1993 -- is no previous subprogram declaration, the stub acts as a spec, and
1994 -- provides the defining entity for the subprogram.
1996 procedure Analyze_Subprogram_Body_Stub
(N
: Node_Id
) is
1998 Opts
: Config_Switches_Type
;
2001 Check_Stub_Level
(N
);
2003 -- Verify that the identifier for the stub is unique within this
2004 -- declarative part.
2006 if Nkind_In
(Parent
(N
), N_Block_Statement
,
2010 Decl
:= First
(Declarations
(Parent
(N
)));
2011 while Present
(Decl
) and then Decl
/= N
loop
2012 if Nkind
(Decl
) = N_Subprogram_Body_Stub
2013 and then (Chars
(Defining_Unit_Name
(Specification
(Decl
))) =
2014 Chars
(Defining_Unit_Name
(Specification
(N
))))
2016 Error_Msg_N
("identifier for stub is not unique", N
);
2023 -- Retain and restore the configuration options of the enclosing context
2024 -- as the proper body may introduce a set of its own.
2026 Save_Opt_Config_Switches
(Opts
);
2028 -- Treat stub as a body, which checks conformance if there is a previous
2029 -- declaration, or else introduces entity and its signature.
2031 Analyze_Subprogram_Body
(N
);
2032 Analyze_Proper_Body
(N
, Empty
);
2034 Restore_Opt_Config_Switches
(Opts
);
2035 end Analyze_Subprogram_Body_Stub
;
2037 ---------------------
2038 -- Analyze_Subunit --
2039 ---------------------
2041 -- A subunit is compiled either by itself (for semantic checking) or as
2042 -- part of compiling the parent (for code generation). In either case, by
2043 -- the time we actually process the subunit, the parent has already been
2044 -- installed and analyzed. The node N is a compilation unit, whose context
2045 -- needs to be treated here, because we come directly here from the parent
2046 -- without calling Analyze_Compilation_Unit.
2048 -- The compilation context includes the explicit context of the subunit,
2049 -- and the context of the parent, together with the parent itself. In order
2050 -- to compile the current context, we remove the one inherited from the
2051 -- parent, in order to have a clean visibility table. We restore the parent
2052 -- context before analyzing the proper body itself. On exit, we remove only
2053 -- the explicit context of the subunit.
2055 -- WARNING: This routine manages SPARK regions. Return statements must be
2056 -- replaced by gotos which jump to the end of the routine and restore the
2059 procedure Analyze_Subunit
(N
: Node_Id
) is
2060 Lib_Unit
: constant Node_Id
:= Library_Unit
(N
);
2061 Par_Unit
: constant Entity_Id
:= Current_Scope
;
2063 Lib_Spec
: Node_Id
:= Library_Unit
(Lib_Unit
);
2064 Num_Scopes
: Nat
:= 0;
2065 Use_Clauses
: array (1 .. Scope_Stack
.Last
) of Node_Id
;
2066 Enclosing_Child
: Entity_Id
:= Empty
;
2067 Svg
: constant Suppress_Record
:= Scope_Suppress
;
2069 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
2070 Cunit_Boolean_Restrictions_Save
;
2071 -- Save non-partition wide restrictions before processing the subunit.
2072 -- All subunits are analyzed with config restrictions reset and we need
2073 -- to restore these saved values at the end.
2075 procedure Analyze_Subunit_Context
;
2076 -- Capture names in use clauses of the subunit. This must be done before
2077 -- re-installing parent declarations, because items in the context must
2078 -- not be hidden by declarations local to the parent.
2080 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
);
2081 -- Recursive procedure to restore scope of all ancestors of subunit,
2082 -- from outermost in. If parent is not a subunit, the call to install
2083 -- context installs context of spec and (if parent is a child unit) the
2084 -- context of its parents as well. It is confusing that parents should
2085 -- be treated differently in both cases, but the semantics are just not
2088 procedure Re_Install_Use_Clauses
;
2089 -- As part of the removal of the parent scope, the use clauses are
2090 -- removed, to be reinstalled when the context of the subunit has been
2091 -- analyzed. Use clauses may also have been affected by the analysis of
2092 -- the context of the subunit, so they have to be applied again, to
2093 -- insure that the compilation environment of the rest of the parent
2094 -- unit is identical.
2096 procedure Remove_Scope
;
2097 -- Remove current scope from scope stack, and preserve the list of use
2098 -- clauses in it, to be reinstalled after context is analyzed.
2100 -----------------------------
2101 -- Analyze_Subunit_Context --
2102 -----------------------------
2104 procedure Analyze_Subunit_Context
is
2107 Unit_Name
: Entity_Id
;
2110 Analyze_Context
(N
);
2111 Check_No_Elab_Code_All
(N
);
2113 -- Make withed units immediately visible. If child unit, make the
2114 -- ultimate parent immediately visible.
2116 Item
:= First
(Context_Items
(N
));
2117 while Present
(Item
) loop
2118 if Nkind
(Item
) = N_With_Clause
then
2120 -- Protect frontend against previous errors in context clauses
2122 if Nkind
(Name
(Item
)) /= N_Selected_Component
then
2123 if Error_Posted
(Item
) then
2127 -- If a subunits has serious syntax errors, the context
2128 -- may not have been loaded. Add a harmless unit name to
2129 -- attempt processing.
2131 if Serious_Errors_Detected
> 0
2132 and then No
(Entity
(Name
(Item
)))
2134 Set_Entity
(Name
(Item
), Standard_Standard
);
2137 Unit_Name
:= Entity
(Name
(Item
));
2139 Set_Is_Visible_Lib_Unit
(Unit_Name
);
2140 exit when Scope
(Unit_Name
) = Standard_Standard
;
2141 Unit_Name
:= Scope
(Unit_Name
);
2143 if No
(Unit_Name
) then
2144 Check_Error_Detected
;
2149 if not Is_Immediately_Visible
(Unit_Name
) then
2150 Set_Is_Immediately_Visible
(Unit_Name
);
2151 Set_Context_Installed
(Item
);
2156 elsif Nkind
(Item
) = N_Use_Package_Clause
then
2157 Nam
:= First
(Names
(Item
));
2158 while Present
(Nam
) loop
2163 elsif Nkind
(Item
) = N_Use_Type_Clause
then
2164 Nam
:= First
(Subtype_Marks
(Item
));
2165 while Present
(Nam
) loop
2174 -- Reset visibility of withed units. They will be made visible again
2175 -- when we install the subunit context.
2177 Item
:= First
(Context_Items
(N
));
2178 while Present
(Item
) loop
2179 if Nkind
(Item
) = N_With_Clause
2181 -- Protect frontend against previous errors in context clauses
2183 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2184 and then not Error_Posted
(Item
)
2186 Unit_Name
:= Entity
(Name
(Item
));
2188 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
2189 exit when Scope
(Unit_Name
) = Standard_Standard
;
2190 Unit_Name
:= Scope
(Unit_Name
);
2193 if Context_Installed
(Item
) then
2194 Set_Is_Immediately_Visible
(Unit_Name
, False);
2195 Set_Context_Installed
(Item
, False);
2201 end Analyze_Subunit_Context
;
2203 ------------------------
2204 -- Re_Install_Parents --
2205 ------------------------
2207 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
) is
2211 if Nkind
(Unit
(L
)) = N_Subunit
then
2212 Re_Install_Parents
(Library_Unit
(L
), Scope
(Scop
));
2215 Install_Context
(L
);
2217 -- If the subunit occurs within a child unit, we must restore the
2218 -- immediate visibility of any siblings that may occur in context.
2220 if Present
(Enclosing_Child
) then
2221 Install_Siblings
(Enclosing_Child
, L
);
2226 if Scop
/= Par_Unit
then
2227 Set_Is_Immediately_Visible
(Scop
);
2230 -- Make entities in scope visible again. For child units, restore
2231 -- visibility only if they are actually in context.
2233 E
:= First_Entity
(Current_Scope
);
2234 while Present
(E
) loop
2235 if not Is_Child_Unit
(E
) or else Is_Visible_Lib_Unit
(E
) then
2236 Set_Is_Immediately_Visible
(E
);
2242 -- A subunit appears within a body, and for a nested subunits all the
2243 -- parents are bodies. Restore full visibility of their private
2246 if Is_Package_Or_Generic_Package
(Scop
) then
2247 Set_In_Package_Body
(Scop
);
2248 Install_Private_Declarations
(Scop
);
2250 end Re_Install_Parents
;
2252 ----------------------------
2253 -- Re_Install_Use_Clauses --
2254 ----------------------------
2256 procedure Re_Install_Use_Clauses
is
2259 for J
in reverse 1 .. Num_Scopes
loop
2260 U
:= Use_Clauses
(J
);
2261 Scope_Stack
.Table
(Scope_Stack
.Last
- J
+ 1).First_Use_Clause
:= U
;
2262 Install_Use_Clauses
(U
, Force_Installation
=> True);
2264 end Re_Install_Use_Clauses
;
2270 procedure Remove_Scope
is
2274 Num_Scopes
:= Num_Scopes
+ 1;
2275 Use_Clauses
(Num_Scopes
) :=
2276 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
;
2278 E
:= First_Entity
(Current_Scope
);
2279 while Present
(E
) loop
2280 Set_Is_Immediately_Visible
(E
, False);
2284 if Is_Child_Unit
(Current_Scope
) then
2285 Enclosing_Child
:= Current_Scope
;
2291 Saved_SM
: SPARK_Mode_Type
:= SPARK_Mode
;
2292 Saved_SMP
: Node_Id
:= SPARK_Mode_Pragma
;
2293 -- Save the SPARK mode-related data to restore on exit. Removing
2294 -- enclosing scopes and contexts to provide a clean environment for the
2295 -- context of the subunit will eliminate any previously set SPARK_Mode.
2297 -- Start of processing for Analyze_Subunit
2300 -- For subunit in main extended unit, we reset the configuration values
2301 -- for the non-partition-wide restrictions. For other units reset them.
2303 if In_Extended_Main_Source_Unit
(N
) then
2304 Restore_Config_Cunit_Boolean_Restrictions
;
2306 Reset_Cunit_Boolean_Restrictions
;
2311 Nam
: Node_Id
:= Name
(Unit
(N
));
2314 if Nkind
(Nam
) = N_Selected_Component
then
2315 Nam
:= Selector_Name
(Nam
);
2318 Check_Identifier
(Nam
, Par_Unit
);
2322 if not Is_Empty_List
(Context_Items
(N
)) then
2324 -- Save current use clauses
2327 Remove_Context
(Lib_Unit
);
2329 -- Now remove parents and their context, including enclosing subunits
2330 -- and the outer parent body which is not a subunit.
2332 if Present
(Lib_Spec
) then
2333 Remove_Context
(Lib_Spec
);
2335 while Nkind
(Unit
(Lib_Spec
)) = N_Subunit
loop
2336 Lib_Spec
:= Library_Unit
(Lib_Spec
);
2338 Remove_Context
(Lib_Spec
);
2341 if Nkind
(Unit
(Lib_Unit
)) = N_Subunit
then
2345 if Nkind
(Unit
(Lib_Spec
)) = N_Package_Body
then
2346 Remove_Context
(Library_Unit
(Lib_Spec
));
2350 Set_Is_Immediately_Visible
(Par_Unit
, False);
2352 Analyze_Subunit_Context
;
2354 -- Take into account the effect of any SPARK_Mode configuration
2355 -- pragma, which takes precedence over a different value of
2356 -- SPARK_Mode inherited from the context of the stub.
2358 if SPARK_Mode
/= None
then
2359 Saved_SM
:= SPARK_Mode
;
2360 Saved_SMP
:= SPARK_Mode_Pragma
;
2363 Re_Install_Parents
(Lib_Unit
, Par_Unit
);
2364 Set_Is_Immediately_Visible
(Par_Unit
);
2366 -- If the context includes a child unit of the parent of the subunit,
2367 -- the parent will have been removed from visibility, after compiling
2368 -- that cousin in the context. The visibility of the parent must be
2369 -- restored now. This also applies if the context includes another
2370 -- subunit of the same parent which in turn includes a child unit in
2373 if Is_Package_Or_Generic_Package
(Par_Unit
) then
2374 if not Is_Immediately_Visible
(Par_Unit
)
2375 or else (Present
(First_Entity
(Par_Unit
))
2377 Is_Immediately_Visible
(First_Entity
(Par_Unit
)))
2379 Set_Is_Immediately_Visible
(Par_Unit
);
2380 Install_Visible_Declarations
(Par_Unit
);
2381 Install_Private_Declarations
(Par_Unit
);
2385 Re_Install_Use_Clauses
;
2386 Install_Context
(N
);
2388 -- Restore state of suppress flags for current body
2390 Scope_Suppress
:= Svg
;
2392 -- If the subunit is within a child unit, then siblings of any parent
2393 -- unit that appear in the context clause of the subunit must also be
2394 -- made immediately visible.
2396 if Present
(Enclosing_Child
) then
2397 Install_Siblings
(Enclosing_Child
, N
);
2401 Generate_Parent_References
(Unit
(N
), Par_Unit
);
2403 -- Reinstall the SPARK_Mode which was in effect prior to any scope and
2404 -- context manipulations, taking into account a possible SPARK_Mode
2405 -- configuration pragma if present.
2407 Install_SPARK_Mode
(Saved_SM
, Saved_SMP
);
2409 Analyze
(Proper_Body
(Unit
(N
)));
2412 -- The subunit may contain a with_clause on a sibling of some ancestor.
2413 -- Removing the context will remove from visibility those ancestor child
2414 -- units, which must be restored to the visibility they have in the
2417 if Present
(Enclosing_Child
) then
2422 while Present
(C
) and then C
/= Standard_Standard
loop
2423 Set_Is_Immediately_Visible
(C
);
2424 Set_Is_Visible_Lib_Unit
(C
);
2430 -- Deal with restore of restrictions
2432 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
2433 end Analyze_Subunit
;
2435 ----------------------------
2436 -- Analyze_Task_Body_Stub --
2437 ----------------------------
2439 procedure Analyze_Task_Body_Stub
(N
: Node_Id
) is
2440 Loc
: constant Source_Ptr
:= Sloc
(N
);
2441 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
2444 Check_Stub_Level
(N
);
2446 -- First occurrence of name may have been as an incomplete type
2448 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2449 Nam
:= Full_View
(Nam
);
2452 if No
(Nam
) or else not Is_Task_Type
(Etype
(Nam
)) then
2453 Error_Msg_N
("missing specification for task body", N
);
2456 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
2457 Set_Ekind
(Defining_Entity
(N
), E_Task_Body
);
2458 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
2459 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2461 -- Check for duplicate stub, if so give message and terminate
2463 if Has_Completion
(Etype
(Nam
)) then
2464 Error_Msg_N
("duplicate stub for task", N
);
2467 Set_Has_Completion
(Etype
(Nam
));
2470 Analyze_Proper_Body
(N
, Etype
(Nam
));
2472 -- Set elaboration flag to indicate that entity is callable. This
2473 -- cannot be done in the expansion of the body itself, because the
2474 -- proper body is not in a declarative part. This is only done if
2475 -- expansion is active, because the context may be generic and the
2476 -- flag not defined yet.
2478 if Expander_Active
then
2480 Make_Assignment_Statement
(Loc
,
2482 Make_Identifier
(Loc
,
2483 Chars
=> New_External_Name
(Chars
(Etype
(Nam
)), 'E')),
2484 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
2487 end Analyze_Task_Body_Stub
;
2489 -------------------------
2490 -- Analyze_With_Clause --
2491 -------------------------
2493 -- Analyze the declaration of a unit in a with clause. At end, label the
2494 -- with clause with the defining entity for the unit.
2496 procedure Analyze_With_Clause
(N
: Node_Id
) is
2498 -- Retrieve the original kind of the unit node, before analysis. If it
2499 -- is a subprogram instantiation, its analysis below will rewrite the
2500 -- node as the declaration of the wrapper package. If the same
2501 -- instantiation appears indirectly elsewhere in the context, it will
2502 -- have been analyzed already.
2504 Unit_Kind
: constant Node_Kind
:=
2505 Nkind
(Original_Node
(Unit
(Library_Unit
(N
))));
2506 Nam
: constant Node_Id
:= Name
(N
);
2508 Par_Name
: Entity_Id
;
2513 -- Set True if the unit currently being compiled is an internal unit
2515 Restriction_Violation
: Boolean := False;
2516 -- Set True if a with violates a restriction, no point in giving any
2517 -- warnings if we have this definite error.
2519 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
2522 U
:= Unit
(Library_Unit
(N
));
2524 -- If this is an internal unit which is a renaming, then this is a
2525 -- violation of No_Obsolescent_Features.
2527 -- Note: this is not quite right if the user defines one of these units
2528 -- himself, but that's a marginal case, and fixing it is hard ???
2530 if Restriction_Check_Required
(No_Obsolescent_Features
) then
2531 if In_Predefined_Renaming
(U
) then
2532 Check_Restriction
(No_Obsolescent_Features
, N
);
2533 Restriction_Violation
:= True;
2537 -- Check No_Implementation_Units violation
2539 if Restriction_Check_Required
(No_Implementation_Units
) then
2540 if Not_Impl_Defined_Unit
(Get_Source_Unit
(U
)) then
2543 Check_Restriction
(No_Implementation_Units
, Nam
);
2544 Restriction_Violation
:= True;
2548 -- Several actions are skipped for dummy packages (those supplied for
2549 -- with's where no matching file could be found). Such packages are
2550 -- identified by the Sloc value being set to No_Location.
2552 if Limited_Present
(N
) then
2554 -- Ada 2005 (AI-50217): Build visibility structures but do not
2555 -- analyze the unit.
2557 -- If the designated unit is a predefined unit, which might be used
2558 -- implicitly through the rtsfind machinery, a limited with clause
2559 -- on such a unit is usually pointless, because run-time units are
2560 -- unlikely to appear in mutually dependent units, and because this
2561 -- disables the rtsfind mechanism. We transform such limited with
2562 -- clauses into regular with clauses.
2564 if Sloc
(U
) /= No_Location
then
2565 if In_Predefined_Unit
(U
)
2567 -- In ASIS mode the rtsfind mechanism plays no role, and
2568 -- we need to maintain the original tree structure, so
2569 -- this transformation is not performed in this case.
2571 and then not ASIS_Mode
2573 Set_Limited_Present
(N
, False);
2574 Analyze_With_Clause
(N
);
2576 Build_Limited_Views
(N
);
2583 -- If we are compiling under "don't quit" mode (-gnatq) and we have
2584 -- already detected serious errors then we mark the with-clause nodes as
2585 -- analyzed before the corresponding compilation unit is analyzed. This
2586 -- is done here to protect the frontend against never ending recursion
2587 -- caused by circularities in the sources (because the previous errors
2588 -- may break the regular machine of the compiler implemented in
2589 -- Load_Unit to detect circularities).
2591 if Serious_Errors_Detected
> 0 and then Try_Semantics
then
2595 Semantics
(Library_Unit
(N
));
2597 Intunit
:= Is_Internal_Unit
(Current_Sem_Unit
);
2599 if Sloc
(U
) /= No_Location
then
2601 -- Check restrictions, except that we skip the check if this is an
2602 -- internal unit unless we are compiling the internal unit as the
2603 -- main unit. We also skip this for dummy packages.
2605 Check_Restriction_No_Dependence
(Nam
, N
);
2607 if not Intunit
or else Current_Sem_Unit
= Main_Unit
then
2608 Check_Restricted_Unit
(Unit_Name
(Get_Source_Unit
(U
)), N
);
2611 -- Deal with special case of GNAT.Current_Exceptions which interacts
2612 -- with the optimization of local raise statements into gotos.
2614 if Nkind
(Nam
) = N_Selected_Component
2615 and then Nkind
(Prefix
(Nam
)) = N_Identifier
2616 and then Chars
(Prefix
(Nam
)) = Name_Gnat
2617 and then Nam_In
(Chars
(Selector_Name
(Nam
)),
2618 Name_Most_Recent_Exception
,
2619 Name_Exception_Traces
)
2621 Check_Restriction
(No_Exception_Propagation
, N
);
2622 Special_Exception_Package_Used
:= True;
2625 -- Check for inappropriate with of internal implementation unit if we
2626 -- are not compiling an internal unit and also check for withing unit
2627 -- in wrong version of Ada. Do not issue these messages for implicit
2628 -- with's generated by the compiler itself.
2630 if Implementation_Unit_Warnings
2631 and then not Intunit
2632 and then not Implicit_With
(N
)
2633 and then not Restriction_Violation
2636 U_Kind
: constant Kind_Of_Unit
:=
2637 Get_Kind_Of_Unit
(Get_Source_Unit
(U
));
2640 if U_Kind
= Implementation_Unit
then
2641 Error_Msg_F
("& is an internal 'G'N'A'T unit?i?", Name
(N
));
2643 -- Add alternative name if available, otherwise issue a
2644 -- general warning message.
2646 if Error_Msg_Strlen
/= 0 then
2647 Error_Msg_F
("\use ""~"" instead?i?", Name
(N
));
2650 ("\use of this unit is non-portable " &
2651 "and version-dependent?i?", Name
(N
));
2654 elsif U_Kind
= Ada_2005_Unit
2655 and then Ada_Version
< Ada_2005
2656 and then Warn_On_Ada_2005_Compatibility
2658 Error_Msg_N
("& is an Ada 2005 unit?i?", Name
(N
));
2660 elsif U_Kind
= Ada_2012_Unit
2661 and then Ada_Version
< Ada_2012
2662 and then Warn_On_Ada_2012_Compatibility
2664 Error_Msg_N
("& is an Ada 2012 unit?i?", Name
(N
));
2670 -- Semantic analysis of a generic unit is performed on a copy of
2671 -- the original tree. Retrieve the entity on which semantic info
2672 -- actually appears.
2674 if Unit_Kind
in N_Generic_Declaration
then
2675 E_Name
:= Defining_Entity
(U
);
2677 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2678 -- the case of an instantiation, semantic analysis above will have
2679 -- replaced the unit by its instantiated version. If the instance body
2680 -- has been generated, the instance now denotes the body entity. For
2681 -- visibility purposes we need the entity of its spec.
2683 elsif (Unit_Kind
= N_Package_Instantiation
2684 or else Nkind
(Original_Node
(Unit
(Library_Unit
(N
)))) =
2685 N_Package_Instantiation
)
2686 and then Nkind
(U
) = N_Package_Body
2688 E_Name
:= Corresponding_Spec
(U
);
2690 elsif Unit_Kind
= N_Package_Instantiation
2691 and then Nkind
(U
) = N_Package_Instantiation
2692 and then Present
(Instance_Spec
(U
))
2694 -- If the instance has not been rewritten as a package declaration,
2695 -- then it appeared already in a previous with clause. Retrieve
2696 -- the entity from the previous instance.
2698 E_Name
:= Defining_Entity
(Specification
(Instance_Spec
(U
)));
2700 elsif Unit_Kind
in N_Subprogram_Instantiation
then
2702 -- The visible subprogram is created during instantiation, and is
2703 -- an attribute of the wrapper package. We retrieve the wrapper
2704 -- package directly from the instantiation node. If the instance
2705 -- is inlined the unit is still an instantiation. Otherwise it has
2706 -- been rewritten as the declaration of the wrapper itself.
2708 if Nkind
(U
) in N_Subprogram_Instantiation
then
2711 (Defining_Entity
(Specification
(Instance_Spec
(U
))));
2713 E_Name
:= Related_Instance
(Defining_Entity
(U
));
2716 elsif Unit_Kind
= N_Package_Renaming_Declaration
2717 or else Unit_Kind
in N_Generic_Renaming_Declaration
2719 E_Name
:= Defining_Entity
(U
);
2721 elsif Unit_Kind
= N_Subprogram_Body
2722 and then Nkind
(Name
(N
)) = N_Selected_Component
2723 and then not Acts_As_Spec
(Library_Unit
(N
))
2725 -- For a child unit that has no spec, one has been created and
2726 -- analyzed. The entity required is that of the spec.
2728 E_Name
:= Corresponding_Spec
(U
);
2731 E_Name
:= Defining_Entity
(U
);
2734 if Nkind
(Name
(N
)) = N_Selected_Component
then
2736 -- Child unit in a with clause
2738 Change_Selected_Component_To_Expanded_Name
(Name
(N
));
2740 -- If this is a child unit without a spec, and it has been analyzed
2741 -- already, a declaration has been created for it. The with_clause
2742 -- must reflect the actual body, and not the generated declaration,
2743 -- to prevent spurious binding errors involving an out-of-date spec.
2744 -- Note that this can only happen if the unit includes more than one
2745 -- with_clause for the child unit (e.g. in separate subunits).
2747 if Unit_Kind
= N_Subprogram_Declaration
2748 and then Analyzed
(Library_Unit
(N
))
2749 and then not Comes_From_Source
(Library_Unit
(N
))
2751 Set_Library_Unit
(N
,
2752 Cunit
(Get_Source_Unit
(Corresponding_Body
(U
))));
2756 -- Restore style checks
2758 Style_Check
:= Save_Style_Check
;
2760 -- Record the reference, but do NOT set the unit as referenced, we want
2761 -- to consider the unit as unreferenced if this is the only reference
2764 Set_Entity_With_Checks
(Name
(N
), E_Name
);
2765 Generate_Reference
(E_Name
, Name
(N
), 'w', Set_Ref
=> False);
2767 -- Generate references and check No_Dependence restriction for parents
2769 if Is_Child_Unit
(E_Name
) then
2770 Pref
:= Prefix
(Name
(N
));
2771 Par_Name
:= Scope
(E_Name
);
2772 while Nkind
(Pref
) = N_Selected_Component
loop
2773 Change_Selected_Component_To_Expanded_Name
(Pref
);
2775 if Present
(Entity
(Selector_Name
(Pref
)))
2777 Present
(Renamed_Entity
(Entity
(Selector_Name
(Pref
))))
2778 and then Entity
(Selector_Name
(Pref
)) /= Par_Name
2780 -- The prefix is a child unit that denotes a renaming declaration.
2781 -- Replace the prefix directly with the renamed unit, because the
2782 -- rest of the prefix is irrelevant to the visibility of the real
2785 Rewrite
(Pref
, New_Occurrence_Of
(Par_Name
, Sloc
(Pref
)));
2789 Set_Entity_With_Checks
(Pref
, Par_Name
);
2791 Generate_Reference
(Par_Name
, Pref
);
2792 Check_Restriction_No_Dependence
(Pref
, N
);
2793 Pref
:= Prefix
(Pref
);
2795 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2796 -- is set to Standard_Standard, and no attempt should be made to
2797 -- further unwind scopes.
2799 if Par_Name
/= Standard_Standard
then
2800 Par_Name
:= Scope
(Par_Name
);
2803 -- Abandon processing in case of previous errors
2805 if No
(Par_Name
) then
2806 Check_Error_Detected
;
2811 if Present
(Entity
(Pref
))
2812 and then not Analyzed
(Parent
(Parent
(Entity
(Pref
))))
2814 -- If the entity is set without its unit being compiled, the
2815 -- original parent is a renaming, and Par_Name is the renamed
2816 -- entity. For visibility purposes, we need the original entity,
2817 -- which must be analyzed now because Load_Unit directly retrieves
2818 -- the renamed unit, and the renaming declaration itself has not
2821 Analyze
(Parent
(Parent
(Entity
(Pref
))));
2822 pragma Assert
(Renamed_Object
(Entity
(Pref
)) = Par_Name
);
2823 Par_Name
:= Entity
(Pref
);
2826 -- Guard against missing or misspelled child units
2828 if Present
(Par_Name
) then
2829 Set_Entity_With_Checks
(Pref
, Par_Name
);
2830 Generate_Reference
(Par_Name
, Pref
);
2833 pragma Assert
(Serious_Errors_Detected
/= 0);
2835 -- Mark the node to indicate that a related error has been posted.
2836 -- This defends further compilation passes against improper use of
2837 -- the invalid WITH clause node.
2839 Set_Error_Posted
(N
);
2840 Set_Name
(N
, Error
);
2845 -- If the withed unit is System, and a system extension pragma is
2846 -- present, compile the extension now, rather than waiting for a
2847 -- visibility check on a specific entity.
2849 if Chars
(E_Name
) = Name_System
2850 and then Scope
(E_Name
) = Standard_Standard
2851 and then Present
(System_Extend_Unit
)
2852 and then Present_System_Aux
(N
)
2854 -- If the extension is not present, an error will have been emitted
2859 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2860 -- to private_with units; they will be made visible later (just before
2861 -- the private part is analyzed)
2863 if Private_Present
(N
) then
2864 Set_Is_Immediately_Visible
(E_Name
, False);
2867 -- Propagate Fatal_Error setting from with'ed unit to current unit
2869 case Fatal_Error
(Get_Source_Unit
(Library_Unit
(N
))) is
2871 -- Nothing to do if with'ed unit had no error
2876 -- If with'ed unit had a detected fatal error, propagate it
2878 when Error_Detected
=>
2879 Set_Fatal_Error
(Current_Sem_Unit
, Error_Detected
);
2881 -- If with'ed unit had an ignored error, then propagate it but do not
2882 -- overide an existring setting.
2884 when Error_Ignored
=>
2885 if Fatal_Error
(Current_Sem_Unit
) = None
then
2886 Set_Fatal_Error
(Current_Sem_Unit
, Error_Ignored
);
2890 Mark_Ghost_Clause
(N
);
2891 end Analyze_With_Clause
;
2893 ------------------------------
2894 -- Check_Private_Child_Unit --
2895 ------------------------------
2897 procedure Check_Private_Child_Unit
(N
: Node_Id
) is
2898 Lib_Unit
: constant Node_Id
:= Unit
(N
);
2900 Curr_Unit
: Entity_Id
;
2901 Sub_Parent
: Node_Id
;
2902 Priv_Child
: Entity_Id
;
2903 Par_Lib
: Entity_Id
;
2906 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean;
2907 -- Returns true if and only if the library unit is declared with
2908 -- an explicit designation of private.
2910 -----------------------------
2911 -- Is_Private_Library_Unit --
2912 -----------------------------
2914 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean is
2915 Comp_Unit
: constant Node_Id
:= Parent
(Unit_Declaration_Node
(Unit
));
2918 return Private_Present
(Comp_Unit
);
2919 end Is_Private_Library_Unit
;
2921 -- Start of processing for Check_Private_Child_Unit
2924 if Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subprogram_Body
) then
2925 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(N
)));
2926 Par_Lib
:= Curr_Unit
;
2928 elsif Nkind
(Lib_Unit
) = N_Subunit
then
2930 -- The parent is itself a body. The parent entity is to be found in
2931 -- the corresponding spec.
2933 Sub_Parent
:= Library_Unit
(N
);
2934 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(Sub_Parent
)));
2936 -- If the parent itself is a subunit, Curr_Unit is the entity of the
2937 -- enclosing body, retrieve the spec entity which is the proper
2938 -- ancestor we need for the following tests.
2940 if Ekind
(Curr_Unit
) = E_Package_Body
then
2941 Curr_Unit
:= Spec_Entity
(Curr_Unit
);
2944 Par_Lib
:= Curr_Unit
;
2947 Curr_Unit
:= Defining_Entity
(Lib_Unit
);
2949 Par_Lib
:= Curr_Unit
;
2950 Par_Spec
:= Parent_Spec
(Lib_Unit
);
2952 if No
(Par_Spec
) then
2955 Par_Lib
:= Defining_Entity
(Unit
(Par_Spec
));
2959 -- Loop through context items
2961 Item
:= First
(Context_Items
(N
));
2962 while Present
(Item
) loop
2964 -- Ada 2005 (AI-262): Allow private_with of a private child package
2965 -- in public siblings
2967 if Nkind
(Item
) = N_With_Clause
2968 and then not Implicit_With
(Item
)
2969 and then not Limited_Present
(Item
)
2970 and then Is_Private_Descendant
(Entity
(Name
(Item
)))
2972 Priv_Child
:= Entity
(Name
(Item
));
2975 Curr_Parent
: Entity_Id
:= Par_Lib
;
2976 Child_Parent
: Entity_Id
:= Scope
(Priv_Child
);
2977 Prv_Ancestor
: Entity_Id
:= Child_Parent
;
2978 Curr_Private
: Boolean := Is_Private_Library_Unit
(Curr_Unit
);
2981 -- If the child unit is a public child then locate the nearest
2982 -- private ancestor. Child_Parent will then be set to the
2983 -- parent of that ancestor.
2985 if not Is_Private_Library_Unit
(Priv_Child
) then
2986 while Present
(Prv_Ancestor
)
2987 and then not Is_Private_Library_Unit
(Prv_Ancestor
)
2989 Prv_Ancestor
:= Scope
(Prv_Ancestor
);
2992 if Present
(Prv_Ancestor
) then
2993 Child_Parent
:= Scope
(Prv_Ancestor
);
2997 while Present
(Curr_Parent
)
2998 and then Curr_Parent
/= Standard_Standard
2999 and then Curr_Parent
/= Child_Parent
3002 Curr_Private
or else Is_Private_Library_Unit
(Curr_Parent
);
3003 Curr_Parent
:= Scope
(Curr_Parent
);
3006 if No
(Curr_Parent
) then
3007 Curr_Parent
:= Standard_Standard
;
3010 if Curr_Parent
/= Child_Parent
then
3011 if Ekind
(Priv_Child
) = E_Generic_Package
3012 and then Chars
(Priv_Child
) in Text_IO_Package_Name
3013 and then Chars
(Scope
(Scope
(Priv_Child
))) = Name_Ada
3016 ("& is a nested package, not a compilation unit",
3017 Name
(Item
), Priv_Child
);
3021 ("unit in with clause is private child unit!", Item
);
3023 ("\current unit must also have parent&!",
3024 Item
, Child_Parent
);
3028 or else Private_Present
(Item
)
3029 or else Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subunit
)
3030 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3031 and then not Acts_As_Spec
(Parent
(Lib_Unit
)))
3037 ("current unit must also be private descendant of&",
3038 Item
, Child_Parent
);
3046 end Check_Private_Child_Unit
;
3048 ----------------------
3049 -- Check_Stub_Level --
3050 ----------------------
3052 procedure Check_Stub_Level
(N
: Node_Id
) is
3053 Par
: constant Node_Id
:= Parent
(N
);
3054 Kind
: constant Node_Kind
:= Nkind
(Par
);
3057 if Nkind_In
(Kind
, N_Package_Body
,
3061 and then Nkind_In
(Parent
(Par
), N_Compilation_Unit
, N_Subunit
)
3065 -- In an instance, a missing stub appears at any level. A warning
3066 -- message will have been emitted already for the missing file.
3068 elsif not In_Instance
then
3069 Error_Msg_N
("stub cannot appear in an inner scope", N
);
3071 elsif Expander_Active
then
3072 Error_Msg_N
("missing proper body", N
);
3074 end Check_Stub_Level
;
3076 ------------------------
3077 -- Expand_With_Clause --
3078 ------------------------
3080 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
) is
3081 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3082 Ent
: constant Entity_Id
:= Entity
(Nam
);
3086 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
;
3087 -- Build name to be used in implicit with_clause. In most cases this
3088 -- is the source name, but if renamings are present we must make the
3089 -- original unit visible, not the one it renames. The entity in the
3090 -- with clause is the renamed unit, but the identifier is the one from
3091 -- the source, which allows us to recover the unit renaming.
3093 ---------------------
3094 -- Build_Unit_Name --
3095 ---------------------
3097 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
is
3102 if Nkind
(Nam
) = N_Identifier
then
3103 return New_Occurrence_Of
(Entity
(Nam
), Loc
);
3106 Ent
:= Entity
(Nam
);
3108 if Present
(Entity
(Selector_Name
(Nam
)))
3109 and then Chars
(Entity
(Selector_Name
(Nam
))) /= Chars
(Ent
)
3111 Nkind
(Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
))))
3112 = N_Package_Renaming_Declaration
3114 -- The name in the with_clause is of the form A.B.C, and B is
3115 -- given by a renaming declaration. In that case we may not
3116 -- have analyzed the unit for B, but replaced it directly in
3117 -- lib-load with the unit it renames. We have to make A.B
3118 -- visible, so analyze the declaration for B now, in case it
3119 -- has not been done yet.
3121 Ent
:= Entity
(Selector_Name
(Nam
));
3124 (Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))));
3128 Make_Expanded_Name
(Loc
,
3129 Chars
=> Chars
(Entity
(Nam
)),
3130 Prefix
=> Build_Unit_Name
(Prefix
(Nam
)),
3131 Selector_Name
=> New_Occurrence_Of
(Ent
, Loc
));
3132 Set_Entity
(Result
, Ent
);
3135 end Build_Unit_Name
;
3137 -- Start of processing for Expand_With_Clause
3141 Make_With_Clause
(Loc
,
3142 Name
=> Build_Unit_Name
(Nam
));
3144 P
:= Parent
(Unit_Declaration_Node
(Ent
));
3145 Set_Library_Unit
(Withn
, P
);
3146 Set_Corresponding_Spec
(Withn
, Ent
);
3147 Set_First_Name
(Withn
, True);
3148 Set_Implicit_With
(Withn
, True);
3150 -- If the unit is a package or generic package declaration, a private_
3151 -- with_clause on a child unit implies that the implicit with on the
3152 -- parent is also private.
3154 if Nkind_In
(Unit
(N
), N_Package_Declaration
,
3155 N_Generic_Package_Declaration
)
3157 Set_Private_Present
(Withn
, Private_Present
(Item
));
3160 Prepend
(Withn
, Context_Items
(N
));
3161 Mark_Rewrite_Insertion
(Withn
);
3162 Install_Withed_Unit
(Withn
);
3164 -- If we have "with X.Y;", we want to recurse on "X", except in the
3165 -- unusual case where X.Y is a renaming of X. In that case, the scope
3166 -- of X will be null.
3168 if Nkind
(Nam
) = N_Expanded_Name
3169 and then Present
(Scope
(Entity
(Prefix
(Nam
))))
3171 Expand_With_Clause
(Item
, Prefix
(Nam
), N
);
3173 end Expand_With_Clause
;
3175 --------------------------------
3176 -- Generate_Parent_References --
3177 --------------------------------
3179 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
) is
3181 P_Name
: Entity_Id
:= P_Id
;
3184 if Nkind
(N
) = N_Subunit
then
3187 Pref
:= Name
(Parent
(Defining_Entity
(N
)));
3190 if Nkind
(Pref
) = N_Expanded_Name
then
3192 -- Done already, if the unit has been compiled indirectly as
3193 -- part of the closure of its context because of inlining.
3198 while Nkind
(Pref
) = N_Selected_Component
loop
3199 Change_Selected_Component_To_Expanded_Name
(Pref
);
3200 Set_Entity
(Pref
, P_Name
);
3201 Set_Etype
(Pref
, Etype
(P_Name
));
3202 Generate_Reference
(P_Name
, Pref
, 'r');
3203 Pref
:= Prefix
(Pref
);
3204 P_Name
:= Scope
(P_Name
);
3207 -- The guard here on P_Name is to handle the error condition where
3208 -- the parent unit is missing because the file was not found.
3210 if Present
(P_Name
) then
3211 Set_Entity
(Pref
, P_Name
);
3212 Set_Etype
(Pref
, Etype
(P_Name
));
3213 Generate_Reference
(P_Name
, Pref
, 'r');
3214 Style
.Check_Identifier
(Pref
, P_Name
);
3216 end Generate_Parent_References
;
3218 ---------------------
3219 -- Has_With_Clause --
3220 ---------------------
3222 function Has_With_Clause
3225 Is_Limited
: Boolean := False) return Boolean
3229 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
;
3230 -- Return the entity for the unit named in a [limited] with clause
3236 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
is
3238 if Nkind
(Name
(Clause
)) = N_Selected_Component
then
3239 return Entity
(Selector_Name
(Name
(Clause
)));
3241 return Entity
(Name
(Clause
));
3245 -- Start of processing for Has_With_Clause
3248 if Present
(Context_Items
(C_Unit
)) then
3249 Item
:= First
(Context_Items
(C_Unit
));
3250 while Present
(Item
) loop
3251 if Nkind
(Item
) = N_With_Clause
3252 and then Limited_Present
(Item
) = Is_Limited
3253 and then Named_Unit
(Item
) = Pack
3263 end Has_With_Clause
;
3265 -----------------------------
3266 -- Implicit_With_On_Parent --
3267 -----------------------------
3269 procedure Implicit_With_On_Parent
3270 (Child_Unit
: Node_Id
;
3273 Loc
: constant Source_Ptr
:= Sloc
(N
);
3274 P
: constant Node_Id
:= Parent_Spec
(Child_Unit
);
3275 P_Unit
: Node_Id
:= Unit
(P
);
3276 P_Name
: constant Entity_Id
:= Get_Parent_Entity
(P_Unit
);
3279 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
;
3280 -- Build prefix of child unit name. Recurse if needed
3282 function Build_Unit_Name
return Node_Id
;
3283 -- If the unit is a child unit, build qualified name with all ancestors
3285 -------------------------
3286 -- Build_Ancestor_Name --
3287 -------------------------
3289 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
is
3290 P_Ref
: constant Node_Id
:=
3291 New_Occurrence_Of
(Defining_Entity
(P
), Loc
);
3292 P_Spec
: Node_Id
:= P
;
3295 -- Ancestor may have been rewritten as a package body. Retrieve
3296 -- the original spec to trace earlier ancestors.
3298 if Nkind
(P
) = N_Package_Body
3299 and then Nkind
(Original_Node
(P
)) = N_Package_Instantiation
3301 P_Spec
:= Original_Node
(P
);
3304 if No
(Parent_Spec
(P_Spec
)) then
3308 Make_Selected_Component
(Loc
,
3309 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Spec
))),
3310 Selector_Name
=> P_Ref
);
3312 end Build_Ancestor_Name
;
3314 ---------------------
3315 -- Build_Unit_Name --
3316 ---------------------
3318 function Build_Unit_Name
return Node_Id
is
3322 if No
(Parent_Spec
(P_Unit
)) then
3323 return New_Occurrence_Of
(P_Name
, Loc
);
3327 Make_Expanded_Name
(Loc
,
3328 Chars
=> Chars
(P_Name
),
3329 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Unit
))),
3330 Selector_Name
=> New_Occurrence_Of
(P_Name
, Loc
));
3331 Set_Entity
(Result
, P_Name
);
3334 end Build_Unit_Name
;
3336 -- Start of processing for Implicit_With_On_Parent
3339 -- The unit of the current compilation may be a package body that
3340 -- replaces an instance node. In this case we need the original instance
3341 -- node to construct the proper parent name.
3343 if Nkind
(P_Unit
) = N_Package_Body
3344 and then Nkind
(Original_Node
(P_Unit
)) = N_Package_Instantiation
3346 P_Unit
:= Original_Node
(P_Unit
);
3349 -- We add the implicit with if the child unit is the current unit being
3350 -- compiled. If the current unit is a body, we do not want to add an
3351 -- implicit_with a second time to the corresponding spec.
3353 if Nkind
(Child_Unit
) = N_Package_Declaration
3354 and then Child_Unit
/= Unit
(Cunit
(Current_Sem_Unit
))
3359 Withn
:= Make_With_Clause
(Loc
, Name
=> Build_Unit_Name
);
3361 Set_Library_Unit
(Withn
, P
);
3362 Set_Corresponding_Spec
(Withn
, P_Name
);
3363 Set_First_Name
(Withn
, True);
3364 Set_Implicit_With
(Withn
, True);
3366 -- Node is placed at the beginning of the context items, so that
3367 -- subsequent use clauses on the parent can be validated.
3369 Prepend
(Withn
, Context_Items
(N
));
3370 Mark_Rewrite_Insertion
(Withn
);
3371 Install_Withed_Unit
(Withn
);
3373 if Is_Child_Spec
(P_Unit
) then
3374 Implicit_With_On_Parent
(P_Unit
, N
);
3376 end Implicit_With_On_Parent
;
3382 function In_Chain
(E
: Entity_Id
) return Boolean is
3386 H
:= Current_Entity
(E
);
3387 while Present
(H
) loop
3398 ---------------------
3399 -- Install_Context --
3400 ---------------------
3402 procedure Install_Context
(N
: Node_Id
) is
3403 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3406 Install_Context_Clauses
(N
);
3408 if Is_Child_Spec
(Lib_Unit
) then
3409 Install_Parents
(Lib_Unit
, Private_Present
(Parent
(Lib_Unit
)));
3412 Install_Limited_Context_Clauses
(N
);
3413 end Install_Context
;
3415 -----------------------------
3416 -- Install_Context_Clauses --
3417 -----------------------------
3419 procedure Install_Context_Clauses
(N
: Node_Id
) is
3420 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3422 Uname_Node
: Entity_Id
;
3423 Check_Private
: Boolean := False;
3424 Decl_Node
: Node_Id
;
3425 Lib_Parent
: Entity_Id
;
3428 -- First skip configuration pragmas at the start of the context. They
3429 -- are not technically part of the context clause, but that's where the
3430 -- parser puts them. Note they were analyzed in Analyze_Context.
3432 Item
:= First
(Context_Items
(N
));
3433 while Present
(Item
)
3434 and then Nkind
(Item
) = N_Pragma
3435 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
3440 -- Loop through the actual context clause items. We process everything
3441 -- except Limited_With clauses in this routine. Limited_With clauses
3442 -- are separately installed (see Install_Limited_Context_Clauses).
3444 while Present
(Item
) loop
3446 -- Case of explicit WITH clause
3448 if Nkind
(Item
) = N_With_Clause
3449 and then not Implicit_With
(Item
)
3451 if Limited_Present
(Item
) then
3453 -- Limited withed units will be installed later
3457 -- If Name (Item) is not an entity name, something is wrong, and
3458 -- this will be detected in due course, for now ignore the item
3460 elsif not Is_Entity_Name
(Name
(Item
)) then
3463 elsif No
(Entity
(Name
(Item
))) then
3464 Set_Entity
(Name
(Item
), Any_Id
);
3468 Uname_Node
:= Entity
(Name
(Item
));
3470 if Is_Private_Descendant
(Uname_Node
) then
3471 Check_Private
:= True;
3474 Install_Withed_Unit
(Item
);
3476 Decl_Node
:= Unit_Declaration_Node
(Uname_Node
);
3478 -- If the unit is a subprogram instance, it appears nested within
3479 -- a package that carries the parent information.
3481 if Is_Generic_Instance
(Uname_Node
)
3482 and then Ekind
(Uname_Node
) /= E_Package
3484 Decl_Node
:= Parent
(Parent
(Decl_Node
));
3487 if Is_Child_Spec
(Decl_Node
) then
3488 if Nkind
(Name
(Item
)) = N_Expanded_Name
then
3489 Expand_With_Clause
(Item
, Prefix
(Name
(Item
)), N
);
3491 -- If not an expanded name, the child unit must be a
3492 -- renaming, nothing to do.
3497 elsif Nkind
(Decl_Node
) = N_Subprogram_Body
3498 and then not Acts_As_Spec
(Parent
(Decl_Node
))
3499 and then Is_Child_Spec
(Unit
(Library_Unit
(Parent
(Decl_Node
))))
3501 Implicit_With_On_Parent
3502 (Unit
(Library_Unit
(Parent
(Decl_Node
))), N
);
3505 -- Check license conditions unless this is a dummy unit
3507 if Sloc
(Library_Unit
(Item
)) /= No_Location
then
3508 License_Check
: declare
3509 Withu
: constant Unit_Number_Type
:=
3510 Get_Source_Unit
(Library_Unit
(Item
));
3511 Withl
: constant License_Type
:=
3512 License
(Source_Index
(Withu
));
3513 Unitl
: constant License_Type
:=
3514 License
(Source_Index
(Current_Sem_Unit
));
3516 procedure License_Error
;
3517 -- Signal error of bad license
3523 procedure License_Error
is
3526 ("license of withed unit & may be inconsistent??",
3530 -- Start of processing for License_Check
3533 -- Exclude license check if withed unit is an internal unit.
3534 -- This situation arises e.g. with the GPL version of GNAT.
3536 if Is_Internal_Unit
(Withu
) then
3539 -- Otherwise check various cases
3551 if Withl
= Restricted
then
3555 when Modified_GPL
=>
3556 if Withl
= Restricted
or else Withl
= GPL
then
3560 when Unrestricted
=>
3567 -- Case of USE PACKAGE clause
3569 elsif Nkind
(Item
) = N_Use_Package_Clause
then
3570 Analyze_Use_Package
(Item
);
3572 -- Case of USE TYPE clause
3574 elsif Nkind
(Item
) = N_Use_Type_Clause
then
3575 Analyze_Use_Type
(Item
);
3579 elsif Nkind
(Item
) = N_Pragma
then
3587 if Is_Child_Spec
(Lib_Unit
) then
3589 -- The unit also has implicit with_clauses on its own parents
3591 if No
(Context_Items
(N
)) then
3592 Set_Context_Items
(N
, New_List
);
3595 Implicit_With_On_Parent
(Lib_Unit
, N
);
3598 -- If the unit is a body, the context of the specification must also
3599 -- be installed. That includes private with_clauses in that context.
3601 if Nkind
(Lib_Unit
) = N_Package_Body
3602 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3603 and then not Acts_As_Spec
(N
))
3605 Install_Context
(Library_Unit
(N
));
3607 -- Only install private with-clauses of a spec that comes from
3608 -- source, excluding specs created for a subprogram body that is
3611 if Comes_From_Source
(Library_Unit
(N
)) then
3612 Install_Private_With_Clauses
3613 (Defining_Entity
(Unit
(Library_Unit
(N
))));
3616 if Is_Child_Spec
(Unit
(Library_Unit
(N
))) then
3618 -- If the unit is the body of a public child unit, the private
3619 -- declarations of the parent must be made visible. If the child
3620 -- unit is private, the private declarations have been installed
3621 -- already in the call to Install_Parents for the spec. Installing
3622 -- private declarations must be done for all ancestors of public
3623 -- child units. In addition, sibling units mentioned in the
3624 -- context clause of the body are directly visible.
3632 Lib_Spec
:= Unit
(Library_Unit
(N
));
3633 while Is_Child_Spec
(Lib_Spec
) loop
3634 P
:= Unit
(Parent_Spec
(Lib_Spec
));
3635 P_Name
:= Defining_Entity
(P
);
3637 if not (Private_Present
(Parent
(Lib_Spec
)))
3638 and then not In_Private_Part
(P_Name
)
3640 Install_Private_Declarations
(P_Name
);
3641 Install_Private_With_Clauses
(P_Name
);
3642 Set_Use
(Private_Declarations
(Specification
(P
)));
3650 -- For a package body, children in context are immediately visible
3652 Install_Siblings
(Defining_Entity
(Unit
(Library_Unit
(N
))), N
);
3655 if Nkind_In
(Lib_Unit
, N_Generic_Package_Declaration
,
3656 N_Generic_Subprogram_Declaration
,
3657 N_Package_Declaration
,
3658 N_Subprogram_Declaration
)
3660 if Is_Child_Spec
(Lib_Unit
) then
3661 Lib_Parent
:= Defining_Entity
(Unit
(Parent_Spec
(Lib_Unit
)));
3662 Set_Is_Private_Descendant
3663 (Defining_Entity
(Lib_Unit
),
3664 Is_Private_Descendant
(Lib_Parent
)
3665 or else Private_Present
(Parent
(Lib_Unit
)));
3668 Set_Is_Private_Descendant
3669 (Defining_Entity
(Lib_Unit
),
3670 Private_Present
(Parent
(Lib_Unit
)));
3674 if Check_Private
then
3675 Check_Private_Child_Unit
(N
);
3677 end Install_Context_Clauses
;
3679 -------------------------------------
3680 -- Install_Limited_Context_Clauses --
3681 -------------------------------------
3683 procedure Install_Limited_Context_Clauses
(N
: Node_Id
) is
3686 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
);
3687 -- Check that the unlimited view of a given compilation_unit is not
3688 -- already visible through "use + renamings".
3690 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
);
3691 -- Check that if a limited_with clause of a given compilation_unit
3692 -- mentions a descendant of a private child of some library unit, then
3693 -- the given compilation_unit must be the declaration of a private
3694 -- descendant of that library unit, or a public descendant of such. The
3695 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3696 -- use entities on the limited with_clauses because their units have not
3697 -- been analyzed, so we have to climb the tree of ancestors looking for
3698 -- private keywords.
3700 procedure Expand_Limited_With_Clause
3701 (Comp_Unit
: Node_Id
;
3704 -- If a child unit appears in a limited_with clause, there are implicit
3705 -- limited_with clauses on all parents that are not already visible
3706 -- through a regular with clause. This procedure creates the implicit
3707 -- limited with_clauses for the parents and loads the corresponding
3708 -- units. The shadow entities are created when the inserted clause is
3709 -- analyzed. Implements Ada 2005 (AI-50217).
3711 ---------------------
3712 -- Check_Renamings --
3713 ---------------------
3715 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
) is
3724 pragma Assert
(Nkind
(W
) = N_With_Clause
);
3726 -- Protect the frontend against previous critical errors
3728 case Nkind
(Unit
(Library_Unit
(W
))) is
3729 when N_Generic_Package_Declaration
3730 | N_Generic_Subprogram_Declaration
3731 | N_Package_Declaration
3732 | N_Subprogram_Declaration
3740 -- Check "use + renamings"
3742 WEnt
:= Defining_Unit_Name
(Specification
(Unit
(Library_Unit
(W
))));
3743 Spec
:= Specification
(Unit
(P
));
3745 Item
:= First
(Visible_Declarations
(Spec
));
3746 while Present
(Item
) loop
3748 -- Look only at use package clauses
3750 if Nkind
(Item
) = N_Use_Package_Clause
then
3752 -- Traverse the list of packages
3754 Nam
:= First
(Names
(Item
));
3755 while Present
(Nam
) loop
3758 pragma Assert
(Present
(Parent
(E
)));
3760 if Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
3761 and then Renamed_Entity
(E
) = WEnt
3763 -- The unlimited view is visible through use clause and
3764 -- renamings. There is no need to generate the error
3765 -- message here because Is_Visible_Through_Renamings
3766 -- takes care of generating the precise error message.
3770 elsif Nkind
(Parent
(E
)) = N_Package_Specification
then
3772 -- The use clause may refer to a local package.
3773 -- Check all the enclosing scopes.
3776 while E2
/= Standard_Standard
and then E2
/= WEnt
loop
3782 ("unlimited view visible through use clause ", W
);
3794 -- Recursive call to check all the ancestors
3796 if Is_Child_Spec
(Unit
(P
)) then
3797 Check_Renamings
(P
=> Parent_Spec
(Unit
(P
)), W
=> W
);
3799 end Check_Renamings
;
3801 ---------------------------------------
3802 -- Check_Private_Limited_Withed_Unit --
3803 ---------------------------------------
3805 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
) is
3806 Curr_Parent
: Node_Id
;
3807 Child_Parent
: Node_Id
;
3808 Curr_Private
: Boolean;
3811 -- Compilation unit of the parent of the withed library unit
3813 Child_Parent
:= Library_Unit
(Item
);
3815 -- If the child unit is a public child, then locate its nearest
3816 -- private ancestor, if any, then Child_Parent will then be set to
3817 -- the parent of that ancestor.
3819 if not Private_Present
(Library_Unit
(Item
)) then
3820 while Present
(Child_Parent
)
3821 and then not Private_Present
(Child_Parent
)
3823 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3826 if No
(Child_Parent
) then
3831 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3833 -- Traverse all the ancestors of the current compilation unit to
3834 -- check if it is a descendant of named library unit.
3836 Curr_Parent
:= Parent
(Item
);
3837 Curr_Private
:= Private_Present
(Curr_Parent
);
3839 while Present
(Parent_Spec
(Unit
(Curr_Parent
)))
3840 and then Curr_Parent
/= Child_Parent
3842 Curr_Parent
:= Parent_Spec
(Unit
(Curr_Parent
));
3843 Curr_Private
:= Curr_Private
or else Private_Present
(Curr_Parent
);
3846 if Curr_Parent
/= Child_Parent
then
3848 ("unit in with clause is private child unit!", Item
);
3850 ("\current unit must also have parent&!",
3851 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3853 elsif Private_Present
(Parent
(Item
))
3854 or else Curr_Private
3855 or else Private_Present
(Item
)
3856 or else Nkind_In
(Unit
(Parent
(Item
)), N_Package_Body
,
3860 -- Current unit is private, of descendant of a private unit
3866 ("current unit must also be private descendant of&",
3867 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3869 end Check_Private_Limited_Withed_Unit
;
3871 --------------------------------
3872 -- Expand_Limited_With_Clause --
3873 --------------------------------
3875 procedure Expand_Limited_With_Clause
3876 (Comp_Unit
: Node_Id
;
3880 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3881 Unum
: Unit_Number_Type
;
3884 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean;
3885 -- Returns true if the context already includes a with_clause for
3886 -- this unit. If the with_clause is non-limited, the unit is fully
3887 -- visible and an implicit limited_with should not be created. If
3888 -- there is already a limited_with clause for W, a second one is
3889 -- simply redundant.
3891 --------------------------
3892 -- Previous_Withed_Unit --
3893 --------------------------
3895 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean is
3899 -- A limited with_clause cannot appear in the same context_clause
3900 -- as a nonlimited with_clause which mentions the same library.
3902 Item
:= First
(Context_Items
(Comp_Unit
));
3903 while Present
(Item
) loop
3904 if Nkind
(Item
) = N_With_Clause
3905 and then Library_Unit
(Item
) = Library_Unit
(W
)
3914 end Previous_Withed_Unit
;
3916 -- Start of processing for Expand_Limited_With_Clause
3919 if Nkind
(Nam
) = N_Identifier
then
3921 -- Create node for name of withed unit
3924 Make_With_Clause
(Loc
,
3925 Name
=> New_Copy
(Nam
));
3927 else pragma Assert
(Nkind
(Nam
) = N_Selected_Component
);
3929 Make_With_Clause
(Loc
,
3930 Name
=> Make_Selected_Component
(Loc
,
3931 Prefix
=> New_Copy_Tree
(Prefix
(Nam
)),
3932 Selector_Name
=> New_Copy
(Selector_Name
(Nam
))));
3933 Set_Parent
(Withn
, Parent
(N
));
3936 Set_Limited_Present
(Withn
);
3937 Set_First_Name
(Withn
);
3938 Set_Implicit_With
(Withn
);
3942 (Load_Name
=> Get_Spec_Name
(Get_Unit_Name
(Nam
)),
3947 -- Do not generate a limited_with_clause on the current unit. This
3948 -- path is taken when a unit has a limited_with clause on one of its
3951 if Unum
= Current_Sem_Unit
then
3955 Set_Library_Unit
(Withn
, Cunit
(Unum
));
3956 Set_Corresponding_Spec
3957 (Withn
, Specification
(Unit
(Cunit
(Unum
))));
3959 if not Previous_Withed_Unit
(Withn
) then
3960 Prepend
(Withn
, Context_Items
(Parent
(N
)));
3961 Mark_Rewrite_Insertion
(Withn
);
3963 -- Add implicit limited_with_clauses for parents of child units
3964 -- mentioned in limited_with clauses.
3966 if Nkind
(Nam
) = N_Selected_Component
then
3967 Expand_Limited_With_Clause
(Comp_Unit
, Prefix
(Nam
), N
);
3972 if not Limited_View_Installed
(Withn
) then
3973 Install_Limited_Withed_Unit
(Withn
);
3976 end Expand_Limited_With_Clause
;
3978 -- Start of processing for Install_Limited_Context_Clauses
3981 Item
:= First
(Context_Items
(N
));
3982 while Present
(Item
) loop
3983 if Nkind
(Item
) = N_With_Clause
3984 and then Limited_Present
(Item
)
3985 and then not Error_Posted
(Item
)
3987 if Nkind
(Name
(Item
)) = N_Selected_Component
then
3988 Expand_Limited_With_Clause
3989 (Comp_Unit
=> N
, Nam
=> Prefix
(Name
(Item
)), N
=> Item
);
3992 Check_Private_Limited_Withed_Unit
(Item
);
3994 if not Implicit_With
(Item
) and then Is_Child_Spec
(Unit
(N
)) then
3995 Check_Renamings
(Parent_Spec
(Unit
(N
)), Item
);
3998 -- A unit may have a limited with on itself if it has a limited
3999 -- with_clause on one of its child units. In that case it is
4000 -- already being compiled and it makes no sense to install its
4003 -- If the item is a limited_private_with_clause, install it if the
4004 -- current unit is a body or if it is a private child. Otherwise
4005 -- the private clause is installed before analyzing the private
4006 -- part of the current unit.
4008 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
)
4009 and then not Limited_View_Installed
(Item
)
4011 not Is_Ancestor_Unit
4012 (Library_Unit
(Item
), Cunit
(Current_Sem_Unit
))
4014 if not Private_Present
(Item
)
4015 or else Private_Present
(N
)
4016 or else Nkind_In
(Unit
(N
), N_Package_Body
,
4020 Install_Limited_Withed_Unit
(Item
);
4028 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
4029 -- looking for incomplete subtype declarations of incomplete types
4030 -- visible through a limited with clause.
4032 if Ada_Version
>= Ada_2005
4033 and then Analyzed
(N
)
4034 and then Nkind
(Unit
(N
)) = N_Package_Declaration
4039 Non_Lim_View
: Entity_Id
;
4042 Decl
:= First
(Visible_Declarations
(Specification
(Unit
(N
))));
4043 while Present
(Decl
) loop
4044 if Nkind
(Decl
) = N_Subtype_Declaration
4046 Ekind
(Defining_Identifier
(Decl
)) = E_Incomplete_Subtype
4048 From_Limited_With
(Defining_Identifier
(Decl
))
4050 Def_Id
:= Defining_Identifier
(Decl
);
4051 Non_Lim_View
:= Non_Limited_View
(Def_Id
);
4053 if not Is_Incomplete_Type
(Non_Lim_View
) then
4055 -- Convert an incomplete subtype declaration into a
4056 -- corresponding non-limited view subtype declaration.
4057 -- This is usually the case when analyzing a body that
4058 -- has regular with clauses, when the spec has limited
4061 -- If the non-limited view is still incomplete, it is
4062 -- the dummy entry already created, and the declaration
4063 -- cannot be reanalyzed. This is the case when installing
4064 -- a parent unit that has limited with-clauses.
4066 Set_Subtype_Indication
(Decl
,
4067 New_Occurrence_Of
(Non_Lim_View
, Sloc
(Def_Id
)));
4068 Set_Etype
(Def_Id
, Non_Lim_View
);
4069 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(Non_Lim_View
)));
4070 Set_Analyzed
(Decl
, False);
4072 -- Reanalyze the declaration, suppressing the call to
4073 -- Enter_Name to avoid duplicate names.
4075 Analyze_Subtype_Declaration
4085 end Install_Limited_Context_Clauses
;
4087 ---------------------
4088 -- Install_Parents --
4089 ---------------------
4091 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean) is
4098 P
:= Unit
(Parent_Spec
(Lib_Unit
));
4099 P_Name
:= Get_Parent_Entity
(P
);
4101 if Etype
(P_Name
) = Any_Type
then
4105 if Ekind
(P_Name
) = E_Generic_Package
4106 and then not Nkind_In
(Lib_Unit
, N_Generic_Subprogram_Declaration
,
4107 N_Generic_Package_Declaration
)
4108 and then Nkind
(Lib_Unit
) not in N_Generic_Renaming_Declaration
4111 ("child of a generic package must be a generic unit", Lib_Unit
);
4113 elsif not Is_Package_Or_Generic_Package
(P_Name
) then
4115 ("parent unit must be package or generic package", Lib_Unit
);
4116 raise Unrecoverable_Error
;
4118 elsif Present
(Renamed_Object
(P_Name
)) then
4119 Error_Msg_N
("parent unit cannot be a renaming", Lib_Unit
);
4120 raise Unrecoverable_Error
;
4122 -- Verify that a child of an instance is itself an instance, or the
4123 -- renaming of one. Given that an instance that is a unit is replaced
4124 -- with a package declaration, check against the original node. The
4125 -- parent may be currently being instantiated, in which case it appears
4126 -- as a declaration, but the generic_parent is already established
4127 -- indicating that we deal with an instance.
4129 elsif Nkind
(Original_Node
(P
)) = N_Package_Instantiation
then
4130 if Nkind
(Lib_Unit
) in N_Renaming_Declaration
4131 or else Nkind
(Original_Node
(Lib_Unit
)) in N_Generic_Instantiation
4133 (Nkind
(Lib_Unit
) = N_Package_Declaration
4134 and then Present
(Generic_Parent
(Specification
(Lib_Unit
))))
4139 ("child of an instance must be an instance or renaming",
4144 -- This is the recursive call that ensures all parents are loaded
4146 if Is_Child_Spec
(P
) then
4148 Is_Private
or else Private_Present
(Parent
(Lib_Unit
)));
4151 -- Now we can install the context for this parent
4153 Install_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4154 Install_Limited_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4155 Install_Siblings
(P_Name
, Parent
(Lib_Unit
));
4157 -- The child unit is in the declarative region of the parent. The parent
4158 -- must therefore appear in the scope stack and be visible, as when
4159 -- compiling the corresponding body. If the child unit is private or it
4160 -- is a package body, private declarations must be accessible as well.
4161 -- Use declarations in the parent must also be installed. Finally, other
4162 -- child units of the same parent that are in the context are
4163 -- immediately visible.
4165 -- Find entity for compilation unit, and set its private descendant
4166 -- status as needed. Indicate that it is a compilation unit, which is
4167 -- redundant in general, but needed if this is a generated child spec
4168 -- for a child body without previous spec.
4170 E_Name
:= Defining_Entity
(Lib_Unit
);
4172 Set_Is_Child_Unit
(E_Name
);
4173 Set_Is_Compilation_Unit
(E_Name
);
4175 Set_Is_Private_Descendant
(E_Name
,
4176 Is_Private_Descendant
(P_Name
)
4177 or else Private_Present
(Parent
(Lib_Unit
)));
4179 P_Spec
:= Package_Specification
(P_Name
);
4180 Push_Scope
(P_Name
);
4182 -- Save current visibility of unit
4184 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
4185 Is_Immediately_Visible
(P_Name
);
4186 Set_Is_Immediately_Visible
(P_Name
);
4187 Install_Visible_Declarations
(P_Name
);
4188 Set_Use
(Visible_Declarations
(P_Spec
));
4190 -- If the parent is a generic unit, its formal part may contain formal
4191 -- packages and use clauses for them.
4193 if Ekind
(P_Name
) = E_Generic_Package
then
4194 Set_Use
(Generic_Formal_Declarations
(Parent
(P_Spec
)));
4197 if Is_Private
or else Private_Present
(Parent
(Lib_Unit
)) then
4198 Install_Private_Declarations
(P_Name
);
4199 Install_Private_With_Clauses
(P_Name
);
4200 Set_Use
(Private_Declarations
(P_Spec
));
4202 end Install_Parents
;
4204 ----------------------------------
4205 -- Install_Private_With_Clauses --
4206 ----------------------------------
4208 procedure Install_Private_With_Clauses
(P
: Entity_Id
) is
4209 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
4213 if Debug_Flag_I
then
4214 Write_Str
("install private with clauses of ");
4215 Write_Name
(Chars
(P
));
4219 if Nkind
(Parent
(Decl
)) = N_Compilation_Unit
then
4220 Item
:= First
(Context_Items
(Parent
(Decl
)));
4221 while Present
(Item
) loop
4222 if Nkind
(Item
) = N_With_Clause
4223 and then Private_Present
(Item
)
4225 -- If the unit is an ancestor of the current one, it is the
4226 -- case of a private limited with clause on a child unit, and
4227 -- the compilation of one of its descendants, In that case the
4228 -- limited view is errelevant.
4230 if Limited_Present
(Item
) then
4231 if not Limited_View_Installed
(Item
)
4233 not Is_Ancestor_Unit
(Library_Unit
(Item
),
4234 Cunit
(Current_Sem_Unit
))
4236 Install_Limited_Withed_Unit
(Item
);
4239 Install_Withed_Unit
(Item
, Private_With_OK
=> True);
4246 end Install_Private_With_Clauses
;
4248 ----------------------
4249 -- Install_Siblings --
4250 ----------------------
4252 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
) is
4258 -- Iterate over explicit with clauses, and check whether the scope of
4259 -- each entity is an ancestor of the current unit, in which case it is
4260 -- immediately visible.
4262 Item
:= First
(Context_Items
(N
));
4263 while Present
(Item
) loop
4265 -- Do not install private_with_clauses declaration, unless unit
4266 -- is itself a private child unit, or is a body. Note that for a
4267 -- subprogram body the private_with_clause does not take effect
4268 -- until after the specification.
4270 if Nkind
(Item
) /= N_With_Clause
4271 or else Implicit_With
(Item
)
4272 or else Limited_Present
(Item
)
4273 or else Error_Posted
(Item
)
4275 -- Skip processing malformed trees
4277 or else (Try_Semantics
4278 and then Nkind
(Name
(Item
)) not in N_Has_Entity
)
4282 elsif not Private_Present
(Item
)
4283 or else Private_Present
(N
)
4284 or else Nkind
(Unit
(N
)) = N_Package_Body
4286 Id
:= Entity
(Name
(Item
));
4288 if Is_Child_Unit
(Id
)
4289 and then Is_Ancestor_Package
(Scope
(Id
), U_Name
)
4291 Set_Is_Immediately_Visible
(Id
);
4293 -- Check for the presence of another unit in the context that
4294 -- may be inadvertently hidden by the child.
4296 Prev
:= Current_Entity
(Id
);
4299 and then Is_Immediately_Visible
(Prev
)
4300 and then not Is_Child_Unit
(Prev
)
4306 Clause
:= First
(Context_Items
(N
));
4307 while Present
(Clause
) loop
4308 if Nkind
(Clause
) = N_With_Clause
4309 and then Entity
(Name
(Clause
)) = Prev
4312 ("child unit& hides compilation unit " &
4313 "with the same name??",
4323 -- The With_Clause may be on a grand-child or one of its further
4324 -- descendants, which makes a child immediately visible. Examine
4325 -- ancestry to determine whether such a child exists. For example,
4326 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4327 -- is immediately visible.
4329 elsif Is_Child_Unit
(Id
) then
4335 while Is_Child_Unit
(Par
) loop
4336 if Is_Ancestor_Package
(Scope
(Par
), U_Name
) then
4337 Set_Is_Immediately_Visible
(Par
);
4346 -- If the item is a private with-clause on a child unit, the parent
4347 -- may have been installed already, but the child unit must remain
4348 -- invisible until installed in a private part or body, unless there
4349 -- is already a regular with_clause for it in the current unit.
4351 elsif Private_Present
(Item
) then
4352 Id
:= Entity
(Name
(Item
));
4354 if Is_Child_Unit
(Id
) then
4358 function In_Context
return Boolean;
4359 -- Scan context of current unit, to check whether there is
4360 -- a with_clause on the same unit as a private with-clause
4361 -- on a parent, in which case child unit is visible. If the
4362 -- unit is a grand-child, the same applies to its parent.
4368 function In_Context
return Boolean is
4371 First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4372 while Present
(Clause
) loop
4373 if Nkind
(Clause
) = N_With_Clause
4374 and then Comes_From_Source
(Clause
)
4375 and then Is_Entity_Name
(Name
(Clause
))
4376 and then not Private_Present
(Clause
)
4378 if Entity
(Name
(Clause
)) = Id
4380 (Nkind
(Name
(Clause
)) = N_Expanded_Name
4381 and then Entity
(Prefix
(Name
(Clause
))) = Id
)
4394 Set_Is_Visible_Lib_Unit
(Id
, In_Context
);
4401 end Install_Siblings
;
4403 ---------------------------------
4404 -- Install_Limited_Withed_Unit --
4405 ---------------------------------
4407 procedure Install_Limited_Withed_Unit
(N
: Node_Id
) is
4408 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
4411 Is_Child_Package
: Boolean := False;
4412 Lim_Header
: Entity_Id
;
4413 Lim_Typ
: Entity_Id
;
4415 procedure Check_Body_Required
;
4416 -- A unit mentioned in a limited with_clause may not be mentioned in
4417 -- a regular with_clause, but must still be included in the current
4418 -- partition. We need to determine whether the unit needs a body, so
4419 -- that the binder can determine the name of the file to be compiled.
4420 -- Checking whether a unit needs a body can be done without semantic
4421 -- analysis, by examining the nature of the declarations in the package.
4423 function Has_Limited_With_Clause
4424 (C_Unit
: Entity_Id
;
4425 Pack
: Entity_Id
) return Boolean;
4426 -- Determine whether any package in the ancestor chain starting with
4427 -- C_Unit has a limited with clause for package Pack.
4429 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean;
4430 -- Check if some package installed though normal with-clauses has a
4431 -- renaming declaration of package P. AARM 10.1.2(21/2).
4433 -------------------------
4434 -- Check_Body_Required --
4435 -------------------------
4437 procedure Check_Body_Required
is
4438 PA
: constant List_Id
:=
4439 Pragmas_After
(Aux_Decls_Node
(Parent
(P_Unit
)));
4441 procedure Check_Declarations
(Spec
: Node_Id
);
4442 -- Recursive procedure that does the work and checks nested packages
4444 ------------------------
4445 -- Check_Declarations --
4446 ------------------------
4448 procedure Check_Declarations
(Spec
: Node_Id
) is
4450 Incomplete_Decls
: constant Elist_Id
:= New_Elmt_List
;
4452 Subp_List
: constant Elist_Id
:= New_Elmt_List
;
4454 procedure Check_Pragma_Import
(P
: Node_Id
);
4455 -- If a pragma import applies to a previous subprogram, the
4456 -- enclosing unit may not need a body. The processing is syntactic
4457 -- and does not require a declaration to be analyzed. The code
4458 -- below also handles pragma Import when applied to a subprogram
4459 -- that renames another. In this case the pragma applies to the
4462 -- Chains of multiple renames are not handled by the code below.
4463 -- It is probably impossible to handle all cases without proper
4464 -- name resolution. In such cases the algorithm is conservative
4465 -- and will indicate that a body is needed???
4467 -------------------------
4468 -- Check_Pragma_Import --
4469 -------------------------
4471 procedure Check_Pragma_Import
(P
: Node_Id
) is
4477 procedure Remove_Homonyms
(E
: Node_Id
);
4478 -- Make one pass over list of subprograms. Called again if
4479 -- subprogram is a renaming. E is known to be an identifier.
4481 ---------------------
4482 -- Remove_Homonyms --
4483 ---------------------
4485 procedure Remove_Homonyms
(E
: Node_Id
) is
4486 R
: Entity_Id
:= Empty
;
4487 -- Name of renamed entity, if any
4490 Subp_Id
:= First_Elmt
(Subp_List
);
4491 while Present
(Subp_Id
) loop
4492 if Chars
(Node
(Subp_Id
)) = Chars
(E
) then
4493 if Nkind
(Parent
(Parent
(Node
(Subp_Id
))))
4494 /= N_Subprogram_Renaming_Declaration
4497 Next_Elmt
(Subp_Id
);
4498 Remove_Elmt
(Subp_List
, Prev_Id
);
4500 R
:= Name
(Parent
(Parent
(Node
(Subp_Id
))));
4504 Next_Elmt
(Subp_Id
);
4509 if Nkind
(R
) = N_Identifier
then
4510 Remove_Homonyms
(R
);
4512 elsif Nkind
(R
) = N_Selected_Component
then
4513 Remove_Homonyms
(Selector_Name
(R
));
4515 -- Renaming of attribute
4521 end Remove_Homonyms
;
4523 -- Start of processing for Check_Pragma_Import
4526 -- Find name of entity in Import pragma. We have not analyzed
4527 -- the construct, so we must guard against syntax errors.
4529 Arg
:= Next
(First
(Pragma_Argument_Associations
(P
)));
4532 or else Nkind
(Expression
(Arg
)) /= N_Identifier
4536 Imported
:= Expression
(Arg
);
4539 Remove_Homonyms
(Imported
);
4540 end Check_Pragma_Import
;
4542 -- Start of processing for Check_Declarations
4545 -- Search for Elaborate Body pragma
4547 Decl
:= First
(Visible_Declarations
(Spec
));
4548 while Present
(Decl
)
4549 and then Nkind
(Decl
) = N_Pragma
4551 if Get_Pragma_Id
(Decl
) = Pragma_Elaborate_Body
then
4552 Set_Body_Required
(Library_Unit
(N
));
4559 -- Look for declarations that require the presence of a body. We
4560 -- have already skipped pragmas at the start of the list.
4562 while Present
(Decl
) loop
4564 -- Subprogram that comes from source means body may be needed.
4565 -- Save for subsequent examination of import pragmas.
4567 if Comes_From_Source
(Decl
)
4568 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4569 N_Subprogram_Renaming_Declaration
,
4570 N_Generic_Subprogram_Declaration
))
4572 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4574 -- Package declaration of generic package declaration. We need
4575 -- to recursively examine nested declarations.
4577 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4578 N_Generic_Package_Declaration
)
4580 Check_Declarations
(Specification
(Decl
));
4582 elsif Nkind
(Decl
) = N_Pragma
4583 and then Pragma_Name
(Decl
) = Name_Import
4585 Check_Pragma_Import
(Decl
);
4591 -- Same set of tests for private part. In addition to subprograms
4592 -- detect the presence of Taft Amendment types (incomplete types
4593 -- completed in the body).
4595 Decl
:= First
(Private_Declarations
(Spec
));
4596 while Present
(Decl
) loop
4597 if Comes_From_Source
(Decl
)
4598 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4599 N_Subprogram_Renaming_Declaration
,
4600 N_Generic_Subprogram_Declaration
))
4602 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4604 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4605 N_Generic_Package_Declaration
)
4607 Check_Declarations
(Specification
(Decl
));
4609 -- Collect incomplete type declarations for separate pass
4611 elsif Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
4612 Append_Elmt
(Decl
, Incomplete_Decls
);
4614 elsif Nkind
(Decl
) = N_Pragma
4615 and then Pragma_Name
(Decl
) = Name_Import
4617 Check_Pragma_Import
(Decl
);
4623 -- Now check incomplete declarations to locate Taft amendment
4624 -- types. This can be done by examining the defining identifiers
4625 -- of type declarations without real semantic analysis.
4631 Inc
:= First_Elmt
(Incomplete_Decls
);
4632 while Present
(Inc
) loop
4633 Decl
:= Next
(Node
(Inc
));
4634 while Present
(Decl
) loop
4635 if Nkind
(Decl
) = N_Full_Type_Declaration
4636 and then Chars
(Defining_Identifier
(Decl
)) =
4637 Chars
(Defining_Identifier
(Node
(Inc
)))
4645 -- If no completion, this is a TAT, and a body is needed
4648 Set_Body_Required
(Library_Unit
(N
));
4656 -- Finally, check whether there are subprograms that still require
4657 -- a body, i.e. are not renamings or null.
4659 if not Is_Empty_Elmt_List
(Subp_List
) then
4665 Subp_Id
:= First_Elmt
(Subp_List
);
4666 Spec
:= Parent
(Node
(Subp_Id
));
4668 while Present
(Subp_Id
) loop
4669 if Nkind
(Parent
(Spec
))
4670 = N_Subprogram_Renaming_Declaration
4674 elsif Nkind
(Spec
) = N_Procedure_Specification
4675 and then Null_Present
(Spec
)
4680 Set_Body_Required
(Library_Unit
(N
));
4684 Next_Elmt
(Subp_Id
);
4688 end Check_Declarations
;
4690 -- Start of processing for Check_Body_Required
4693 -- If this is an imported package (Java and CIL usage) no body is
4694 -- needed. Scan list of pragmas that may follow a compilation unit
4695 -- to look for a relevant pragma Import.
4697 if Present
(PA
) then
4703 while Present
(Prag
) loop
4704 if Nkind
(Prag
) = N_Pragma
4705 and then Get_Pragma_Id
(Prag
) = Pragma_Import
4715 Check_Declarations
(Specification
(P_Unit
));
4716 end Check_Body_Required
;
4718 -----------------------------
4719 -- Has_Limited_With_Clause --
4720 -----------------------------
4722 function Has_Limited_With_Clause
4723 (C_Unit
: Entity_Id
;
4724 Pack
: Entity_Id
) return Boolean
4731 while Present
(Par
) loop
4732 if Ekind
(Par
) /= E_Package
then
4736 -- Retrieve the Compilation_Unit node for Par and determine if
4737 -- its context clauses contain a limited with for Pack.
4739 Par_Unit
:= Parent
(Parent
(Parent
(Par
)));
4741 if Nkind
(Par_Unit
) = N_Package_Declaration
then
4742 Par_Unit
:= Parent
(Par_Unit
);
4745 if Has_With_Clause
(Par_Unit
, Pack
, True) then
4749 -- If there are more ancestors, climb up the tree, otherwise we
4752 if Is_Child_Unit
(Par
) then
4760 end Has_Limited_With_Clause
;
4762 ----------------------------------
4763 -- Is_Visible_Through_Renamings --
4764 ----------------------------------
4766 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean is
4767 Kind
: constant Node_Kind
:=
4768 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
4774 -- Example of the error detected by this subprogram:
4782 -- package Ren_P renames P;
4788 -- limited with P; -- ERROR
4789 -- package R.C is ...
4791 Aux_Unit
:= Cunit
(Current_Sem_Unit
);
4794 Item
:= First
(Context_Items
(Aux_Unit
));
4795 while Present
(Item
) loop
4796 if Nkind
(Item
) = N_With_Clause
4797 and then not Limited_Present
(Item
)
4798 and then Nkind
(Unit
(Library_Unit
(Item
))) =
4799 N_Package_Declaration
4802 First
(Visible_Declarations
4803 (Specification
(Unit
(Library_Unit
(Item
)))));
4804 while Present
(Decl
) loop
4805 if Nkind
(Decl
) = N_Package_Renaming_Declaration
4806 and then Entity
(Name
(Decl
)) = P
4808 -- Generate the error message only if the current unit
4809 -- is a package declaration; in case of subprogram
4810 -- bodies and package bodies we just return True to
4811 -- indicate that the limited view must not be
4814 if Kind
= N_Package_Declaration
then
4816 ("simultaneous visibility of the limited and " &
4817 "unlimited views not allowed", N
);
4818 Error_Msg_Sloc
:= Sloc
(Item
);
4820 ("\\ unlimited view of & visible through the " &
4821 "context clause #", N
, P
);
4822 Error_Msg_Sloc
:= Sloc
(Decl
);
4823 Error_Msg_NE
("\\ and the renaming #", N
, P
);
4836 -- If it is a body not acting as spec, follow pointer to the
4837 -- corresponding spec, otherwise follow pointer to parent spec.
4839 if Present
(Library_Unit
(Aux_Unit
))
4840 and then Nkind_In
(Unit
(Aux_Unit
),
4841 N_Package_Body
, N_Subprogram_Body
)
4843 if Aux_Unit
= Library_Unit
(Aux_Unit
) then
4845 -- Aux_Unit is a body that acts as a spec. Clause has
4846 -- already been flagged as illegal.
4851 Aux_Unit
:= Library_Unit
(Aux_Unit
);
4855 Aux_Unit
:= Parent_Spec
(Unit
(Aux_Unit
));
4858 exit when No
(Aux_Unit
);
4862 end Is_Visible_Through_Renamings
;
4864 -- Start of processing for Install_Limited_Withed_Unit
4867 pragma Assert
(not Limited_View_Installed
(N
));
4869 -- In case of limited with_clause on subprograms, generics, instances,
4870 -- or renamings, the corresponding error was previously posted and we
4871 -- have nothing to do here. If the file is missing altogether, it has
4872 -- no source location.
4874 if Nkind
(P_Unit
) /= N_Package_Declaration
4875 or else Sloc
(P_Unit
) = No_Location
4880 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
4882 -- Handle child packages
4884 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
4885 Is_Child_Package
:= True;
4886 P
:= Defining_Identifier
(P
);
4889 -- Do not install the limited-view if the context of the unit is already
4890 -- available through a regular with clause.
4892 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4893 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4898 -- Do not install the limited-view if the full-view is already visible
4899 -- through renaming declarations.
4901 if Is_Visible_Through_Renamings
(P
) then
4905 -- Do not install the limited view if this is the unit being analyzed.
4906 -- This unusual case will happen when a unit has a limited_with clause
4907 -- on one of its children. The compilation of the child forces the load
4908 -- of the parent which tries to install the limited view of the child
4909 -- again. Installing the limited view must also be disabled when
4910 -- compiling the body of the child unit.
4912 if P
= Cunit_Entity
(Current_Sem_Unit
)
4913 or else (Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4914 and then P
= Main_Unit_Entity
4915 and then Is_Ancestor_Unit
4916 (Cunit
(Main_Unit
), Cunit
(Current_Sem_Unit
)))
4921 -- This scenario is similar to the one above, the difference is that the
4922 -- compilation of sibling Par.Sib forces the load of parent Par which
4923 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
4924 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
4925 -- non-limited views of all entities from Lim_Pack.
4927 -- limited with Lim_Pack; -- [1]
4928 -- package Par is ... package Lim_Pack is ...
4930 -- with Lim_Pack; -- [2]
4931 -- package Par.Sib is ... package body Par.Sib is ...
4933 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4934 -- Sem_Unit is the body of Par.Sib.
4936 if Ekind
(P
) = E_Package
4937 and then Ekind
(Main_Unit_Entity
) = E_Package
4938 and then Is_Child_Unit
(Main_Unit_Entity
)
4940 -- The body has a regular with clause
4942 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4943 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4945 -- One of the ancestors has a limited with clause
4947 and then Nkind
(Parent
(Parent
(Main_Unit_Entity
))) =
4948 N_Package_Specification
4949 and then Has_Limited_With_Clause
(Scope
(Main_Unit_Entity
), P
)
4954 -- A common use of the limited-with is to have a limited-with in the
4955 -- package spec, and a normal with in its package body. For example:
4957 -- limited with X; -- [1]
4961 -- package body A is ...
4963 -- The compilation of A's body installs the context clauses found at [2]
4964 -- and then the context clauses of its specification (found at [1]). As
4965 -- a consequence, at [1] the specification of X has been analyzed and it
4966 -- is immediately visible. According to the semantics of limited-with
4967 -- context clauses we don't install the limited view because the full
4968 -- view of X supersedes its limited view.
4970 if Analyzed
(P_Unit
)
4972 (Is_Immediately_Visible
(P
)
4973 or else (Is_Child_Package
and then Is_Visible_Lib_Unit
(P
)))
4976 -- The presence of both the limited and the analyzed nonlimited view
4977 -- may also be an error, such as an illegal context for a limited
4978 -- with_clause. In that case, do not process the context item at all.
4980 if Error_Posted
(N
) then
4984 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
4988 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4989 while Present
(Item
) loop
4990 if Nkind
(Item
) = N_With_Clause
4991 and then Comes_From_Source
(Item
)
4992 and then Entity
(Name
(Item
)) = P
5001 -- If this is a child body, assume that the nonlimited with_clause
5002 -- appears in an ancestor. Could be refined ???
5006 (Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)))))
5013 -- If in package declaration, nonlimited view brought in from
5014 -- parent unit or some error condition.
5020 if Debug_Flag_I
then
5021 Write_Str
("install limited view of ");
5022 Write_Name
(Chars
(P
));
5026 -- If the unit has not been analyzed and the limited view has not been
5027 -- already installed then we install it.
5029 if not Analyzed
(P_Unit
) then
5030 if not In_Chain
(P
) then
5032 -- Minimum decoration
5034 Set_Ekind
(P
, E_Package
);
5035 Set_Etype
(P
, Standard_Void_Type
);
5036 Set_Scope
(P
, Standard_Standard
);
5037 Set_Is_Visible_Lib_Unit
(P
);
5039 if Is_Child_Package
then
5040 Set_Is_Child_Unit
(P
);
5041 Set_Scope
(P
, Defining_Entity
(Unit
(Parent_Spec
(P_Unit
))));
5044 -- Place entity on visibility structure
5046 Set_Homonym
(P
, Current_Entity
(P
));
5047 Set_Current_Entity
(P
);
5049 if Debug_Flag_I
then
5050 Write_Str
(" (homonym) chain ");
5051 Write_Name
(Chars
(P
));
5055 -- Install the incomplete view. The first element of the limited
5056 -- view is a header (an E_Package entity) used to reference the
5057 -- first shadow entity in the private part of the package.
5059 Lim_Header
:= Limited_View
(P
);
5060 Lim_Typ
:= First_Entity
(Lim_Header
);
5062 while Present
(Lim_Typ
)
5063 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5065 Set_Homonym
(Lim_Typ
, Current_Entity
(Lim_Typ
));
5066 Set_Current_Entity
(Lim_Typ
);
5068 if Debug_Flag_I
then
5069 Write_Str
(" (homonym) chain ");
5070 Write_Name
(Chars
(Lim_Typ
));
5074 Next_Entity
(Lim_Typ
);
5078 -- If the unit appears in a previous regular with_clause, the regular
5079 -- entities of the public part of the withed package must be replaced
5080 -- by the shadow ones.
5082 -- This code must be kept synchronized with the code that replaces the
5083 -- shadow entities by the real entities (see body of Remove_Limited
5084 -- With_Clause); otherwise the contents of the homonym chains are not
5088 -- Hide all the type entities of the public part of the package to
5089 -- avoid its usage. This is needed to cover all the subtype decla-
5090 -- rations because we do not remove them from the homonym chain.
5092 E
:= First_Entity
(P
);
5093 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
5095 Set_Was_Hidden
(E
, Is_Hidden
(E
));
5102 -- Replace the real entities by the shadow entities of the limited
5103 -- view. The first element of the limited view is a header that is
5104 -- used to reference the first shadow entity in the private part
5105 -- of the package. Successive elements are the limited views of the
5106 -- type (including regular incomplete types) declared in the package.
5108 Lim_Header
:= Limited_View
(P
);
5110 Lim_Typ
:= First_Entity
(Lim_Header
);
5111 while Present
(Lim_Typ
)
5112 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5114 pragma Assert
(not In_Chain
(Lim_Typ
));
5116 -- Do not unchain nested packages and child units
5118 if Ekind
(Lim_Typ
) /= E_Package
5119 and then not Is_Child_Unit
(Lim_Typ
)
5125 Prev
:= Current_Entity
(Lim_Typ
);
5128 -- Replace E in the homonyms list, so that the limited view
5129 -- becomes available.
5131 -- If the non-limited view is a record with an anonymous
5132 -- self-referential component, the analysis of the record
5133 -- declaration creates an incomplete type with the same name
5134 -- in order to define an internal access type. The visible
5135 -- entity is now the incomplete type, and that is the one to
5136 -- replace in the visibility structure.
5138 if E
= Non_Limited_View
(Lim_Typ
)
5140 (Ekind
(E
) = E_Incomplete_Type
5141 and then Full_View
(E
) = Non_Limited_View
(Lim_Typ
))
5143 Set_Homonym
(Lim_Typ
, Homonym
(Prev
));
5144 Set_Current_Entity
(Lim_Typ
);
5148 E
:= Homonym
(Prev
);
5150 -- E may have been removed when installing a previous
5151 -- limited_with_clause.
5154 exit when E
= Non_Limited_View
(Lim_Typ
);
5155 Prev
:= Homonym
(Prev
);
5159 Set_Homonym
(Lim_Typ
, Homonym
(Homonym
(Prev
)));
5160 Set_Homonym
(Prev
, Lim_Typ
);
5165 if Debug_Flag_I
then
5166 Write_Str
(" (homonym) chain ");
5167 Write_Name
(Chars
(Lim_Typ
));
5172 Next_Entity
(Lim_Typ
);
5176 -- The package must be visible while the limited-with clause is active
5177 -- because references to the type P.T must resolve in the usual way.
5178 -- In addition, we remember that the limited-view has been installed to
5179 -- uninstall it at the point of context removal.
5181 Set_Is_Immediately_Visible
(P
);
5182 Set_Limited_View_Installed
(N
);
5184 -- If unit has not been analyzed in some previous context, check
5185 -- (imperfectly ???) whether it might need a body.
5187 if not Analyzed
(P_Unit
) then
5188 Check_Body_Required
;
5191 -- If the package in the limited_with clause is a child unit, the clause
5192 -- is unanalyzed and appears as a selected component. Recast it as an
5193 -- expanded name so that the entity can be properly set. Use entity of
5194 -- parent, if available, for higher ancestors in the name.
5196 if Nkind
(Name
(N
)) = N_Selected_Component
then
5204 while Nkind
(Nam
) = N_Selected_Component
5205 and then Present
(Ent
)
5207 Change_Selected_Component_To_Expanded_Name
(Nam
);
5209 -- Set entity of parent identifiers if the unit is a child
5210 -- unit. This ensures that the tree is properly formed from
5211 -- semantic point of view (e.g. for ASIS queries). The unit
5212 -- entities are not fully analyzed, so we need to follow unit
5213 -- links in the tree.
5215 Set_Entity
(Nam
, Ent
);
5217 Nam
:= Prefix
(Nam
);
5220 (Unit
(Parent_Spec
(Unit_Declaration_Node
(Ent
))));
5222 -- Set entity of last ancestor
5224 if Nkind
(Nam
) = N_Identifier
then
5225 Set_Entity
(Nam
, Ent
);
5231 Set_Entity
(Name
(N
), P
);
5232 Set_From_Limited_With
(P
);
5233 end Install_Limited_Withed_Unit
;
5235 -------------------------
5236 -- Install_Withed_Unit --
5237 -------------------------
5239 procedure Install_Withed_Unit
5240 (With_Clause
: Node_Id
;
5241 Private_With_OK
: Boolean := False)
5243 Uname
: constant Entity_Id
:= Entity
(Name
(With_Clause
));
5244 P
: constant Entity_Id
:= Scope
(Uname
);
5247 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5248 -- compiling a package declaration and the Private_With_OK flag was not
5249 -- set by the caller. These declarations will be installed later (before
5250 -- analyzing the private part of the package).
5252 if Private_Present
(With_Clause
)
5253 and then Nkind
(Unit
(Parent
(With_Clause
))) = N_Package_Declaration
5254 and then not (Private_With_OK
)
5259 if Debug_Flag_I
then
5260 if Private_Present
(With_Clause
) then
5261 Write_Str
("install private withed unit ");
5263 Write_Str
("install withed unit ");
5266 Write_Name
(Chars
(Uname
));
5270 -- We do not apply the restrictions to an internal unit unless we are
5271 -- compiling the internal unit as a main unit. This check is also
5272 -- skipped for dummy units (for missing packages).
5274 if Sloc
(Uname
) /= No_Location
5275 and then (not Is_Internal_Unit
(Current_Sem_Unit
)
5276 or else Current_Sem_Unit
= Main_Unit
)
5278 Check_Restricted_Unit
5279 (Unit_Name
(Get_Source_Unit
(Uname
)), With_Clause
);
5282 if P
/= Standard_Standard
then
5284 -- If the unit is not analyzed after analysis of the with clause and
5285 -- it is an instantiation then it awaits a body and is the main unit.
5286 -- Its appearance in the context of some other unit indicates a
5287 -- circular dependency (DEC suite perversity).
5289 if not Analyzed
(Uname
)
5290 and then Nkind
(Parent
(Uname
)) = N_Package_Instantiation
5293 ("instantiation depends on itself", Name
(With_Clause
));
5295 elsif not Is_Visible_Lib_Unit
(Uname
) then
5297 -- Abandon processing in case of previous errors
5299 if No
(Scope
(Uname
)) then
5300 Check_Error_Detected
;
5304 Set_Is_Visible_Lib_Unit
(Uname
);
5306 -- If the unit is a wrapper package for a compilation unit that is
5307 -- a subprogrm instance, indicate that the instance itself is a
5308 -- visible unit. This is necessary if the instance is inlined.
5310 if Is_Wrapper_Package
(Uname
) then
5311 Set_Is_Visible_Lib_Unit
(Related_Instance
(Uname
));
5314 -- If the child unit appears in the context of its parent, it is
5315 -- immediately visible.
5317 if In_Open_Scopes
(Scope
(Uname
)) then
5318 Set_Is_Immediately_Visible
(Uname
);
5321 if Is_Generic_Instance
(Uname
)
5322 and then Ekind
(Uname
) in Subprogram_Kind
5324 -- Set flag as well on the visible entity that denotes the
5325 -- instance, which renames the current one.
5327 Set_Is_Visible_Lib_Unit
5329 (Defining_Entity
(Unit
(Library_Unit
(With_Clause
)))));
5332 -- The parent unit may have been installed already, and may have
5333 -- appeared in a use clause.
5335 if In_Use
(Scope
(Uname
)) then
5336 Set_Is_Potentially_Use_Visible
(Uname
);
5339 Set_Context_Installed
(With_Clause
);
5342 elsif not Is_Immediately_Visible
(Uname
) then
5343 Set_Is_Visible_Lib_Unit
(Uname
);
5345 if not Private_Present
(With_Clause
) or else Private_With_OK
then
5346 Set_Is_Immediately_Visible
(Uname
);
5349 Set_Context_Installed
(With_Clause
);
5352 -- A with-clause overrides a with-type clause: there are no restric-
5353 -- tions on the use of package entities.
5355 if Ekind
(Uname
) = E_Package
then
5356 Set_From_Limited_With
(Uname
, False);
5359 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5360 -- unit if there is a visible homograph for it declared in the same
5361 -- declarative region. This pathological case can only arise when an
5362 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5363 -- G1 has a generic child also named G2, and the context includes with_
5364 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5365 -- of I1.G2 visible as well. If the child unit is named Standard, do
5366 -- not apply the check to the Standard package itself.
5368 if Is_Child_Unit
(Uname
)
5369 and then Is_Visible_Lib_Unit
(Uname
)
5370 and then Ada_Version
>= Ada_2005
5373 Decl1
: constant Node_Id
:= Unit_Declaration_Node
(P
);
5379 U2
:= Homonym
(Uname
);
5380 while Present
(U2
) and then U2
/= Standard_Standard
loop
5382 Decl2
:= Unit_Declaration_Node
(P2
);
5384 if Is_Child_Unit
(U2
) and then Is_Visible_Lib_Unit
(U2
) then
5385 if Is_Generic_Instance
(P
)
5386 and then Nkind
(Decl1
) = N_Package_Declaration
5387 and then Generic_Parent
(Specification
(Decl1
)) = P2
5389 Error_Msg_N
("illegal with_clause", With_Clause
);
5391 ("\child unit has visible homograph" &
5392 " (RM 8.3(26), 10.1.1(19))",
5396 elsif Is_Generic_Instance
(P2
)
5397 and then Nkind
(Decl2
) = N_Package_Declaration
5398 and then Generic_Parent
(Specification
(Decl2
)) = P
5400 -- With_clause for child unit of instance appears before
5401 -- in the context. We want to place the error message on
5402 -- it, not on the generic child unit itself.
5405 Prev_Clause
: Node_Id
;
5408 Prev_Clause
:= First
(List_Containing
(With_Clause
));
5409 while Entity
(Name
(Prev_Clause
)) /= U2
loop
5413 pragma Assert
(Present
(Prev_Clause
));
5414 Error_Msg_N
("illegal with_clause", Prev_Clause
);
5416 ("\child unit has visible homograph" &
5417 " (RM 8.3(26), 10.1.1(19))",
5428 end Install_Withed_Unit
;
5434 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean is
5435 K
: constant Node_Kind
:= Nkind
(Lib_Unit
);
5438 return (K
in N_Generic_Declaration
or else
5439 K
in N_Generic_Instantiation
or else
5440 K
in N_Generic_Renaming_Declaration
or else
5441 K
= N_Package_Declaration
or else
5442 K
= N_Package_Renaming_Declaration
or else
5443 K
= N_Subprogram_Declaration
or else
5444 K
= N_Subprogram_Renaming_Declaration
)
5445 and then Present
(Parent_Spec
(Lib_Unit
));
5448 ------------------------------------
5449 -- Is_Legal_Shadow_Entity_In_Body --
5450 ------------------------------------
5452 function Is_Legal_Shadow_Entity_In_Body
(T
: Entity_Id
) return Boolean is
5453 C_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5455 return Nkind
(Unit
(C_Unit
)) = N_Package_Body
5458 (C_Unit
, Cunit_Entity
(Get_Source_Unit
(Non_Limited_View
(T
))));
5459 end Is_Legal_Shadow_Entity_In_Body
;
5461 ----------------------
5462 -- Is_Ancestor_Unit --
5463 ----------------------
5465 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean is
5466 E1
: constant Entity_Id
:= Defining_Entity
(Unit
(U1
));
5469 if Nkind_In
(Unit
(U2
), N_Package_Body
, N_Subprogram_Body
) then
5470 E2
:= Defining_Entity
(Unit
(Library_Unit
(U2
)));
5471 return Is_Ancestor_Package
(E1
, E2
);
5475 end Is_Ancestor_Unit
;
5477 -----------------------
5478 -- Load_Needed_Body --
5479 -----------------------
5481 -- N is a generic unit named in a with clause, or else it is a unit that
5482 -- contains a generic unit or an inlined function. In order to perform an
5483 -- instantiation, the body of the unit must be present. If the unit itself
5484 -- is generic, we assume that an instantiation follows, and load & analyze
5485 -- the body unconditionally. This forces analysis of the spec as well.
5487 -- If the unit is not generic, but contains a generic unit, it is loaded on
5488 -- demand, at the point of instantiation (see ch12).
5490 procedure Load_Needed_Body
5493 Do_Analyze
: Boolean := True)
5495 Body_Name
: Unit_Name_Type
;
5496 Unum
: Unit_Number_Type
;
5498 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
5499 -- The loading and analysis is done with style checks off
5502 if not GNAT_Mode
then
5503 Style_Check
:= False;
5506 Body_Name
:= Get_Body_Name
(Get_Unit_Name
(Unit
(N
)));
5509 (Load_Name
=> Body_Name
,
5515 if Unum
= No_Unit
then
5519 Compiler_State
:= Analyzing
; -- reset after load
5521 if Fatal_Error
(Unum
) /= Error_Detected
or else Try_Semantics
then
5522 if Debug_Flag_L
then
5523 Write_Str
("*** Loaded generic body");
5528 Semantics
(Cunit
(Unum
));
5535 Style_Check
:= Save_Style_Check
;
5536 end Load_Needed_Body
;
5538 -------------------------
5539 -- Build_Limited_Views --
5540 -------------------------
5542 procedure Build_Limited_Views
(N
: Node_Id
) is
5543 Unum
: constant Unit_Number_Type
:=
5544 Get_Source_Unit
(Library_Unit
(N
));
5545 Is_Analyzed
: constant Boolean := Analyzed
(Cunit
(Unum
));
5547 Shadow_Pack
: Entity_Id
;
5548 -- The corresponding shadow entity of the withed package. This entity
5549 -- offers incomplete views of packages and types as well as abstract
5550 -- views of states and variables declared within.
5552 Last_Shadow
: Entity_Id
:= Empty
;
5553 -- The last shadow entity created by routine Build_Shadow_Entity
5555 procedure Build_Shadow_Entity
5558 Shadow
: out Entity_Id
;
5559 Is_Tagged
: Boolean := False);
5560 -- Create a shadow entity that hides Ent and offers an abstract or
5561 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5562 -- should be set when Ent is a tagged type. The generated entity is
5563 -- added to Lim_Header. This routine updates the value of Last_Shadow.
5565 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5566 -- Perform minimal decoration of a package or its corresponding shadow
5567 -- entity denoted by Ent. Scop is the proper scope.
5569 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5570 -- Perform full decoration of an abstract state or its corresponding
5571 -- shadow entity denoted by Ent. Scop is the proper scope.
5573 procedure Decorate_Type
5576 Is_Tagged
: Boolean := False;
5577 Materialize
: Boolean := False);
5578 -- Perform minimal decoration of a type or its corresponding shadow
5579 -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged
5580 -- should be set when Ent is a tagged type. Flag Materialize should be
5581 -- set when Ent is a tagged type and its class-wide type needs to appear
5584 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5585 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5588 procedure Process_Declarations_And_States
5592 Create_Abstract_Views
: Boolean);
5593 -- Inspect the states of package Pack and declarative list Decls. Create
5594 -- shadow entities for all nested packages, states, types and variables
5595 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5596 -- be set when the abstract states and variables need to be processed.
5598 -------------------------
5599 -- Build_Shadow_Entity --
5600 -------------------------
5602 procedure Build_Shadow_Entity
5605 Shadow
: out Entity_Id
;
5606 Is_Tagged
: Boolean := False)
5609 Shadow
:= Make_Temporary
(Sloc
(Ent
), 'Z');
5611 -- The shadow entity must share the same name and parent as the
5614 Set_Chars
(Shadow
, Chars
(Ent
));
5615 Set_Parent
(Shadow
, Parent
(Ent
));
5617 -- The abstract view of a variable is a state, not another variable
5619 if Ekind
(Ent
) = E_Variable
then
5620 Set_Ekind
(Shadow
, E_Abstract_State
);
5622 Set_Ekind
(Shadow
, Ekind
(Ent
));
5625 Set_Is_Internal
(Shadow
);
5626 Set_From_Limited_With
(Shadow
);
5628 -- Add the new shadow entity to the limited view of the package
5630 Last_Shadow
:= Shadow
;
5631 Append_Entity
(Shadow
, Shadow_Pack
);
5633 -- Perform context-specific decoration of the shadow entity
5635 if Ekind
(Ent
) = E_Abstract_State
then
5636 Decorate_State
(Shadow
, Scop
);
5637 Set_Non_Limited_View
(Shadow
, Ent
);
5639 elsif Ekind
(Ent
) = E_Package
then
5640 Decorate_Package
(Shadow
, Scop
);
5642 elsif Is_Type
(Ent
) then
5643 Decorate_Type
(Shadow
, Scop
, Is_Tagged
);
5644 Set_Non_Limited_View
(Shadow
, Ent
);
5647 Set_Non_Limited_View
5648 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Ent
));
5651 if Is_Incomplete_Or_Private_Type
(Ent
) then
5652 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
5655 elsif Ekind
(Ent
) = E_Variable
then
5656 Decorate_State
(Shadow
, Scop
);
5657 Set_Non_Limited_View
(Shadow
, Ent
);
5659 end Build_Shadow_Entity
;
5661 ----------------------
5662 -- Decorate_Package --
5663 ----------------------
5665 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5667 Set_Ekind
(Ent
, E_Package
);
5668 Set_Etype
(Ent
, Standard_Void_Type
);
5669 Set_Scope
(Ent
, Scop
);
5670 end Decorate_Package
;
5672 --------------------
5673 -- Decorate_State --
5674 --------------------
5676 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5678 Set_Ekind
(Ent
, E_Abstract_State
);
5679 Set_Etype
(Ent
, Standard_Void_Type
);
5680 Set_Scope
(Ent
, Scop
);
5681 Set_Encapsulating_State
(Ent
, Empty
);
5688 procedure Decorate_Type
5691 Is_Tagged
: Boolean := False;
5692 Materialize
: Boolean := False)
5697 -- An unanalyzed type or a shadow entity of a type is treated as an
5698 -- incomplete type, and carries the corresponding attributes.
5700 Set_Ekind
(Ent
, E_Incomplete_Type
);
5701 Set_Etype
(Ent
, Ent
);
5702 Set_Full_View
(Ent
, Empty
);
5703 Set_Is_First_Subtype
(Ent
);
5704 Set_Scope
(Ent
, Scop
);
5705 Set_Stored_Constraint
(Ent
, No_Elist
);
5706 Init_Size_Align
(Ent
);
5708 if From_Limited_With
(Ent
) then
5709 Set_Private_Dependents
(Ent
, New_Elmt_List
);
5712 -- A tagged type and its corresponding shadow entity share one common
5713 -- class-wide type. The list of primitive operations for the shadow
5717 Set_Is_Tagged_Type
(Ent
);
5718 Set_Direct_Primitive_Operations
(Ent
, New_Elmt_List
);
5722 (E_Void
, Scope
(Ent
), Sloc
(Ent
), Ent
, 'C', 0, 'T');
5724 Set_Class_Wide_Type
(Ent
, CW_Typ
);
5726 -- Set parent to be the same as the parent of the tagged type.
5727 -- We need a parent field set, and it is supposed to point to
5728 -- the declaration of the type. The tagged type declaration
5729 -- essentially declares two separate types, the tagged type
5730 -- itself and the corresponding class-wide type, so it is
5731 -- reasonable for the parent fields to point to the declaration
5734 Set_Parent
(CW_Typ
, Parent
(Ent
));
5736 Set_Ekind
(CW_Typ
, E_Class_Wide_Type
);
5737 Set_Class_Wide_Type
(CW_Typ
, CW_Typ
);
5738 Set_Etype
(CW_Typ
, Ent
);
5739 Set_Equivalent_Type
(CW_Typ
, Empty
);
5740 Set_From_Limited_With
(CW_Typ
, From_Limited_With
(Ent
));
5741 Set_Has_Unknown_Discriminants
(CW_Typ
);
5742 Set_Is_First_Subtype
(CW_Typ
);
5743 Set_Is_Tagged_Type
(CW_Typ
);
5744 Set_Materialize_Entity
(CW_Typ
, Materialize
);
5745 Set_Scope
(CW_Typ
, Scop
);
5746 Init_Size_Align
(CW_Typ
);
5750 -----------------------
5751 -- Decorate_Variable --
5752 -----------------------
5754 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5756 Set_Ekind
(Ent
, E_Variable
);
5757 Set_Etype
(Ent
, Standard_Void_Type
);
5758 Set_Scope
(Ent
, Scop
);
5759 end Decorate_Variable
;
5761 -------------------------------------
5762 -- Process_Declarations_And_States --
5763 -------------------------------------
5765 procedure Process_Declarations_And_States
5769 Create_Abstract_Views
: Boolean)
5771 procedure Find_And_Process_States
;
5772 -- Determine whether package Pack defines abstract state either by
5773 -- using an aspect or a pragma. If this is the case, build shadow
5774 -- entities for all abstract states of Pack.
5776 procedure Process_States
(States
: Elist_Id
);
5777 -- Generate shadow entities for all abstract states in list States
5779 -----------------------------
5780 -- Find_And_Process_States --
5781 -----------------------------
5783 procedure Find_And_Process_States
is
5784 procedure Process_State
(State
: Node_Id
);
5785 -- Generate shadow entities for a single abstract state or
5786 -- multiple states expressed as an aggregate.
5792 procedure Process_State
(State
: Node_Id
) is
5793 Loc
: constant Source_Ptr
:= Sloc
(State
);
5800 -- Multiple abstract states appear as an aggregate
5802 if Nkind
(State
) = N_Aggregate
then
5803 Elmt
:= First
(Expressions
(State
));
5804 while Present
(Elmt
) loop
5805 Process_State
(Elmt
);
5811 -- A null state has no abstract view
5813 elsif Nkind
(State
) = N_Null
then
5816 -- State declaration with various options appears as an
5817 -- extension aggregate.
5819 elsif Nkind
(State
) = N_Extension_Aggregate
then
5820 Decl
:= Ancestor_Part
(State
);
5822 -- Simple state declaration
5824 elsif Nkind
(State
) = N_Identifier
then
5827 -- Possibly an illegal state declaration
5833 -- Abstract states are elaborated when the related pragma is
5834 -- elaborated. Since the withed package is not analyzed yet,
5835 -- the entities of the abstract states are not available. To
5836 -- overcome this complication, create the entities now and
5837 -- store them in their respective declarations. The entities
5838 -- are later used by routine Create_Abstract_State to declare
5839 -- and enter the states into visibility.
5841 if No
(Entity
(Decl
)) then
5842 Id
:= Make_Defining_Identifier
(Loc
, Chars
(Decl
));
5844 Set_Entity
(Decl
, Id
);
5845 Set_Parent
(Id
, State
);
5846 Decorate_State
(Id
, Scop
);
5848 -- Otherwise the package was previously withed
5851 Id
:= Entity
(Decl
);
5854 Build_Shadow_Entity
(Id
, Scop
, Dummy
);
5859 Pack_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Pack
);
5863 -- Start of processing for Find_And_Process_States
5866 -- Find aspect Abstract_State
5868 Asp
:= First
(Aspect_Specifications
(Pack_Decl
));
5869 while Present
(Asp
) loop
5870 if Chars
(Identifier
(Asp
)) = Name_Abstract_State
then
5871 Process_State
(Expression
(Asp
));
5879 -- Find pragma Abstract_State by inspecting the declarations
5881 Decl
:= First
(Decls
);
5882 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
5883 if Pragma_Name
(Decl
) = Name_Abstract_State
then
5886 (First
(Pragma_Argument_Associations
(Decl
))));
5893 end Find_And_Process_States
;
5895 --------------------
5896 -- Process_States --
5897 --------------------
5899 procedure Process_States
(States
: Elist_Id
) is
5904 Elmt
:= First_Elmt
(States
);
5905 while Present
(Elmt
) loop
5906 Build_Shadow_Entity
(Node
(Elmt
), Scop
, Dummy
);
5914 Is_Tagged
: Boolean;
5920 -- Start of processing for Process_Declarations_And_States
5923 -- Build abstract views for all states defined in the package
5925 if Create_Abstract_Views
then
5927 -- When a package has been analyzed, all states are stored in list
5928 -- Abstract_States. Generate the shadow entities directly.
5931 if Present
(Abstract_States
(Pack
)) then
5932 Process_States
(Abstract_States
(Pack
));
5935 -- The package may declare abstract states by using an aspect or a
5936 -- pragma. Attempt to locate one of these construct and if found,
5937 -- build the shadow entities.
5940 Find_And_Process_States
;
5944 -- Inspect the declarative list, looking for nested packages, types
5945 -- and variable declarations.
5947 Decl
:= First
(Decls
);
5948 while Present
(Decl
) loop
5952 if Nkind
(Decl
) = N_Package_Declaration
then
5953 Def_Id
:= Defining_Entity
(Decl
);
5955 -- Perform minor decoration when the withed package has not
5958 if not Is_Analyzed
then
5959 Decorate_Package
(Def_Id
, Scop
);
5962 -- Create a shadow entity that offers a limited view of all
5963 -- visible types declared within.
5965 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5967 Process_Declarations_And_States
5969 Decls
=> Visible_Declarations
(Specification
(Decl
)),
5971 Create_Abstract_Views
=> Create_Abstract_Views
);
5975 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
5976 N_Incomplete_Type_Declaration
,
5977 N_Private_Extension_Declaration
,
5978 N_Private_Type_Declaration
,
5979 N_Protected_Type_Declaration
,
5980 N_Task_Type_Declaration
)
5982 Def_Id
:= Defining_Entity
(Decl
);
5984 -- Determine whether the type is tagged. Note that packages
5985 -- included via a limited with clause are not always analyzed,
5986 -- hence the tree lookup rather than the use of attribute
5989 if Nkind
(Decl
) = N_Full_Type_Declaration
then
5990 Def
:= Type_Definition
(Decl
);
5993 (Nkind
(Def
) = N_Record_Definition
5994 and then Tagged_Present
(Def
))
5996 (Nkind
(Def
) = N_Derived_Type_Definition
5997 and then Present
(Record_Extension_Part
(Def
)));
5999 elsif Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
6000 N_Private_Type_Declaration
)
6002 Is_Tagged
:= Tagged_Present
(Decl
);
6004 elsif Nkind
(Decl
) = N_Private_Extension_Declaration
then
6011 -- Perform minor decoration when the withed package has not
6014 if not Is_Analyzed
then
6015 Decorate_Type
(Def_Id
, Scop
, Is_Tagged
, True);
6018 -- Create a shadow entity that hides the type and offers an
6019 -- incomplete view of the said type.
6021 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
, Is_Tagged
);
6025 elsif Create_Abstract_Views
6026 and then Nkind
(Decl
) = N_Object_Declaration
6027 and then not Constant_Present
(Decl
)
6029 Def_Id
:= Defining_Entity
(Decl
);
6031 -- Perform minor decoration when the withed package has not
6034 if not Is_Analyzed
then
6035 Decorate_Variable
(Def_Id
, Scop
);
6038 -- Create a shadow entity that hides the variable and offers an
6039 -- abstract view of the said variable.
6041 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
6046 end Process_Declarations_And_States
;
6050 Nam
: constant Node_Id
:= Name
(N
);
6051 Pack
: constant Entity_Id
:= Cunit_Entity
(Unum
);
6053 Last_Public_Shadow
: Entity_Id
:= Empty
;
6054 Private_Shadow
: Entity_Id
;
6057 -- Start of processing for Build_Limited_Views
6060 pragma Assert
(Limited_Present
(N
));
6062 -- A library_item mentioned in a limited_with_clause is a package
6063 -- declaration, not a subprogram declaration, generic declaration,
6064 -- generic instantiation, or package renaming declaration.
6066 case Nkind
(Unit
(Library_Unit
(N
))) is
6067 when N_Package_Declaration
=>
6070 when N_Subprogram_Declaration
=>
6071 Error_Msg_N
("subprograms not allowed in limited with_clauses", N
);
6074 when N_Generic_Package_Declaration
6075 | N_Generic_Subprogram_Declaration
6077 Error_Msg_N
("generics not allowed in limited with_clauses", N
);
6080 when N_Generic_Instantiation
=>
6082 ("generic instantiations not allowed in limited with_clauses",
6086 when N_Generic_Renaming_Declaration
=>
6088 ("generic renamings not allowed in limited with_clauses", N
);
6091 when N_Subprogram_Renaming_Declaration
=>
6093 ("renamed subprograms not allowed in limited with_clauses", N
);
6096 when N_Package_Renaming_Declaration
=>
6098 ("renamed packages not allowed in limited with_clauses", N
);
6102 raise Program_Error
;
6105 -- The withed unit may not be analyzed, but the with calause itself
6106 -- must be minimally decorated. This ensures that the checks on unused
6107 -- with clauses also process limieted withs.
6109 Set_Ekind
(Pack
, E_Package
);
6110 Set_Etype
(Pack
, Standard_Void_Type
);
6112 if Is_Entity_Name
(Nam
) then
6113 Set_Entity
(Nam
, Pack
);
6115 elsif Nkind
(Nam
) = N_Selected_Component
then
6116 Set_Entity
(Selector_Name
(Nam
), Pack
);
6119 -- Check if the chain is already built
6121 Spec
:= Specification
(Unit
(Library_Unit
(N
)));
6123 if Limited_View_Installed
(Spec
) then
6127 -- Create the shadow package wich hides the withed unit and provides
6128 -- incomplete view of all types and packages declared within.
6130 Shadow_Pack
:= Make_Temporary
(Sloc
(N
), 'Z');
6131 Set_Ekind
(Shadow_Pack
, E_Package
);
6132 Set_Is_Internal
(Shadow_Pack
);
6133 Set_Limited_View
(Pack
, Shadow_Pack
);
6135 -- Inspect the abstract states and visible declarations of the withed
6136 -- unit and create shadow entities that hide existing packages, states,
6137 -- variables and types.
6139 Process_Declarations_And_States
6141 Decls
=> Visible_Declarations
(Spec
),
6143 Create_Abstract_Views
=> True);
6145 Last_Public_Shadow
:= Last_Shadow
;
6147 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6148 -- to accommodate limited private with clauses.
6150 Process_Declarations_And_States
6152 Decls
=> Private_Declarations
(Spec
),
6154 Create_Abstract_Views
=> False);
6156 if Present
(Last_Public_Shadow
) then
6157 Private_Shadow
:= Next_Entity
(Last_Public_Shadow
);
6159 Private_Shadow
:= First_Entity
(Shadow_Pack
);
6162 Set_First_Private_Entity
(Shadow_Pack
, Private_Shadow
);
6163 Set_Limited_View_Installed
(Spec
);
6164 end Build_Limited_Views
;
6166 ----------------------------
6167 -- Check_No_Elab_Code_All --
6168 ----------------------------
6170 procedure Check_No_Elab_Code_All
(N
: Node_Id
) is
6172 if Present
(No_Elab_Code_All_Pragma
)
6173 and then In_Extended_Main_Source_Unit
(N
)
6174 and then Present
(Context_Items
(N
))
6177 CL
: constant List_Id
:= Context_Items
(N
);
6182 while Present
(CI
) loop
6183 if Nkind
(CI
) = N_With_Clause
6185 No_Elab_Code_All
(Get_Source_Unit
(Library_Unit
(CI
)))
6187 -- In GNATprove mode, some runtime units are implicitly
6188 -- loaded to make their entities available for analysis. In
6189 -- this case, ignore violations of No_Elaboration_Code_All
6190 -- for this special analysis mode.
6193 (GNATprove_Mode
and then Implicit_With
(CI
))
6195 Error_Msg_Sloc
:= Sloc
(No_Elab_Code_All_Pragma
);
6197 ("violation of No_Elaboration_Code_All#", CI
);
6199 ("\unit& does not have No_Elaboration_Code_All",
6200 CI
, Entity
(Name
(CI
)));
6207 end Check_No_Elab_Code_All
;
6209 -------------------------------
6210 -- Check_Body_Needed_For_SAL --
6211 -------------------------------
6213 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
) is
6214 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean;
6215 -- Determine whether use of entity E might require the presence of its
6216 -- body. For a package this requires a recursive traversal of all nested
6219 -----------------------
6220 -- Entity_Needs_Body --
6221 -----------------------
6223 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean is
6227 if Is_Subprogram
(E
) and then Has_Pragma_Inline
(E
) then
6230 elsif Ekind_In
(E
, E_Generic_Function
, E_Generic_Procedure
) then
6232 -- A generic subprogram always requires the presence of its
6233 -- body because an instantiation needs both templates. The only
6234 -- exceptions is a generic subprogram renaming. In this case the
6235 -- body is needed only when the template is declared outside the
6236 -- compilation unit being checked.
6238 if Present
(Renamed_Entity
(E
)) then
6239 return not Within_Scope
(E
, Unit_Name
);
6244 elsif Ekind
(E
) = E_Generic_Package
6246 Nkind
(Unit_Declaration_Node
(E
)) = N_Generic_Package_Declaration
6247 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6251 elsif Ekind
(E
) = E_Package
6252 and then Nkind
(Unit_Declaration_Node
(E
)) = N_Package_Declaration
6253 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6255 Ent
:= First_Entity
(E
);
6256 while Present
(Ent
) loop
6257 if Entity_Needs_Body
(Ent
) then
6269 end Entity_Needs_Body
;
6271 -- Start of processing for Check_Body_Needed_For_SAL
6274 if Ekind
(Unit_Name
) = E_Generic_Package
6275 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6276 N_Generic_Package_Declaration
6278 Present
(Corresponding_Body
(Unit_Declaration_Node
(Unit_Name
)))
6280 Set_Body_Needed_For_SAL
(Unit_Name
);
6282 elsif Ekind_In
(Unit_Name
, E_Generic_Procedure
, E_Generic_Function
) then
6283 Set_Body_Needed_For_SAL
(Unit_Name
);
6285 elsif Is_Subprogram
(Unit_Name
)
6286 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6287 N_Subprogram_Declaration
6288 and then Has_Pragma_Inline
(Unit_Name
)
6290 Set_Body_Needed_For_SAL
(Unit_Name
);
6292 elsif Ekind
(Unit_Name
) = E_Subprogram_Body
then
6293 Check_Body_Needed_For_SAL
6294 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6296 elsif Ekind
(Unit_Name
) = E_Package
6297 and then Entity_Needs_Body
(Unit_Name
)
6299 Set_Body_Needed_For_SAL
(Unit_Name
);
6301 elsif Ekind
(Unit_Name
) = E_Package_Body
6302 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) = N_Package_Body
6304 Check_Body_Needed_For_SAL
6305 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6307 end Check_Body_Needed_For_SAL
;
6309 --------------------
6310 -- Remove_Context --
6311 --------------------
6313 procedure Remove_Context
(N
: Node_Id
) is
6314 Lib_Unit
: constant Node_Id
:= Unit
(N
);
6317 -- If this is a child unit, first remove the parent units
6319 if Is_Child_Spec
(Lib_Unit
) then
6320 Remove_Parents
(Lib_Unit
);
6323 Remove_Context_Clauses
(N
);
6326 ----------------------------
6327 -- Remove_Context_Clauses --
6328 ----------------------------
6330 procedure Remove_Context_Clauses
(N
: Node_Id
) is
6332 Unit_Name
: Entity_Id
;
6335 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6336 -- limited-views first and regular-views later (to maintain the
6339 -- First Phase: Remove limited_with context clauses
6341 Item
:= First
(Context_Items
(N
));
6342 while Present
(Item
) loop
6344 -- We are interested only in with clauses which got installed
6347 if Nkind
(Item
) = N_With_Clause
6348 and then Limited_Present
(Item
)
6349 and then Limited_View_Installed
(Item
)
6351 Remove_Limited_With_Clause
(Item
);
6357 -- Second Phase: Loop through context items and undo regular
6358 -- with_clauses and use_clauses.
6360 Item
:= First
(Context_Items
(N
));
6361 while Present
(Item
) loop
6363 -- We are interested only in with clauses which got installed on
6364 -- entry, as indicated by their Context_Installed flag set
6366 if Nkind
(Item
) = N_With_Clause
6367 and then Limited_Present
(Item
)
6368 and then Limited_View_Installed
(Item
)
6372 elsif Nkind
(Item
) = N_With_Clause
6373 and then Context_Installed
(Item
)
6375 -- Remove items from one with'ed unit
6377 Unit_Name
:= Entity
(Name
(Item
));
6378 Remove_Unit_From_Visibility
(Unit_Name
);
6379 Set_Context_Installed
(Item
, False);
6381 elsif Nkind
(Item
) = N_Use_Package_Clause
then
6382 End_Use_Package
(Item
);
6384 elsif Nkind
(Item
) = N_Use_Type_Clause
then
6385 End_Use_Type
(Item
);
6390 end Remove_Context_Clauses
;
6392 --------------------------------
6393 -- Remove_Limited_With_Clause --
6394 --------------------------------
6396 procedure Remove_Limited_With_Clause
(N
: Node_Id
) is
6397 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
6400 Lim_Header
: Entity_Id
;
6401 Lim_Typ
: Entity_Id
;
6405 pragma Assert
(Limited_View_Installed
(N
));
6407 -- In case of limited with_clause on subprograms, generics, instances,
6408 -- or renamings, the corresponding error was previously posted and we
6409 -- have nothing to do here.
6411 if Nkind
(P_Unit
) /= N_Package_Declaration
then
6415 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
6417 -- Handle child packages
6419 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
6420 P
:= Defining_Identifier
(P
);
6423 if Debug_Flag_I
then
6424 Write_Str
("remove limited view of ");
6425 Write_Name
(Chars
(P
));
6426 Write_Str
(" from visibility");
6430 -- Prepare the removal of the shadow entities from visibility. The first
6431 -- element of the limited view is a header (an E_Package entity) that is
6432 -- used to reference the first shadow entity in the private part of the
6435 Lim_Header
:= Limited_View
(P
);
6436 Lim_Typ
:= First_Entity
(Lim_Header
);
6438 -- Remove package and shadow entities from visibility if it has not
6441 if not Analyzed
(P_Unit
) then
6443 Set_Is_Immediately_Visible
(P
, False);
6445 while Present
(Lim_Typ
) loop
6447 Next_Entity
(Lim_Typ
);
6450 -- Otherwise this package has already appeared in the closure and its
6451 -- shadow entities must be replaced by its real entities. This code
6452 -- must be kept synchronized with the complementary code in Install
6453 -- Limited_Withed_Unit.
6456 -- If the limited_with_clause is in some other unit in the context
6457 -- then it is not visible in the main unit.
6459 if not In_Extended_Main_Source_Unit
(N
) then
6460 Set_Is_Immediately_Visible
(P
, False);
6463 -- Real entities that are type or subtype declarations were hidden
6464 -- from visibility at the point of installation of the limited-view.
6465 -- Now we recover the previous value of the hidden attribute.
6467 E
:= First_Entity
(P
);
6468 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
6470 Set_Is_Hidden
(E
, Was_Hidden
(E
));
6476 while Present
(Lim_Typ
)
6477 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
6479 -- Nested packages and child units were not unchained
6481 if Ekind
(Lim_Typ
) /= E_Package
6482 and then not Is_Child_Unit
(Non_Limited_View
(Lim_Typ
))
6484 -- If the package has incomplete types, the limited view of the
6485 -- incomplete type is in fact never visible (AI05-129) but we
6486 -- have created a shadow entity E1 for it, that points to E2,
6487 -- a non-limited incomplete type. This in turn has a full view
6488 -- E3 that is the full declaration. There is a corresponding
6489 -- shadow entity E4. When reinstalling the non-limited view,
6490 -- E2 must become the current entity and E3 must be ignored.
6492 E
:= Non_Limited_View
(Lim_Typ
);
6494 if Present
(Current_Entity
(E
))
6495 and then Ekind
(Current_Entity
(E
)) = E_Incomplete_Type
6496 and then Full_View
(Current_Entity
(E
)) = E
6499 -- Lim_Typ is the limited view of a full type declaration
6500 -- that has a previous incomplete declaration, i.e. E3 from
6501 -- the previous description. Nothing to insert.
6506 pragma Assert
(not In_Chain
(E
));
6508 Prev
:= Current_Entity
(Lim_Typ
);
6510 if Prev
= Lim_Typ
then
6511 Set_Current_Entity
(E
);
6514 while Present
(Prev
)
6515 and then Homonym
(Prev
) /= Lim_Typ
6517 Prev
:= Homonym
(Prev
);
6520 if Present
(Prev
) then
6521 Set_Homonym
(Prev
, E
);
6525 -- Preserve structure of homonym chain
6527 Set_Homonym
(E
, Homonym
(Lim_Typ
));
6531 Next_Entity
(Lim_Typ
);
6535 -- Indicate that the limited view of the package is not installed
6537 Set_From_Limited_With
(P
, False);
6538 Set_Limited_View_Installed
(N
, False);
6539 end Remove_Limited_With_Clause
;
6541 --------------------
6542 -- Remove_Parents --
6543 --------------------
6545 procedure Remove_Parents
(Lib_Unit
: Node_Id
) is
6548 P_Spec
: Node_Id
:= Empty
;
6550 Vis
: constant Boolean :=
6551 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
;
6554 if Is_Child_Spec
(Lib_Unit
) then
6555 P_Spec
:= Parent_Spec
(Lib_Unit
);
6557 elsif Nkind
(Lib_Unit
) = N_Package_Body
6558 and then Nkind
(Original_Node
(Lib_Unit
)) = N_Package_Instantiation
6560 P_Spec
:= Parent_Spec
(Original_Node
(Lib_Unit
));
6563 if Present
(P_Spec
) then
6565 P_Name
:= Get_Parent_Entity
(P
);
6566 Remove_Context_Clauses
(P_Spec
);
6567 End_Package_Scope
(P_Name
);
6568 Set_Is_Immediately_Visible
(P_Name
, Vis
);
6570 -- Remove from visibility the siblings as well, which are directly
6571 -- visible while the parent is in scope.
6573 E
:= First_Entity
(P_Name
);
6574 while Present
(E
) loop
6575 if Is_Child_Unit
(E
) then
6576 Set_Is_Immediately_Visible
(E
, False);
6582 Set_In_Package_Body
(P_Name
, False);
6584 -- This is the recursive call to remove the context of any higher
6585 -- level parent. This recursion ensures that all parents are removed
6586 -- in the reverse order of their installation.
6592 ---------------------------------
6593 -- Remove_Private_With_Clauses --
6594 ---------------------------------
6596 procedure Remove_Private_With_Clauses
(Comp_Unit
: Node_Id
) is
6599 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean;
6600 -- Check whether a given unit appears in a regular with_clause. Used to
6601 -- determine whether a private_with_clause, implicit or explicit, should
6604 ----------------------------
6605 -- In_Regular_With_Clause --
6606 ----------------------------
6608 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean
6613 Item
:= First
(Context_Items
(Comp_Unit
));
6614 while Present
(Item
) loop
6615 if Nkind
(Item
) = N_With_Clause
6617 -- The following guard is needed to ensure that the name has
6618 -- been properly analyzed before we go fetching its entity.
6620 and then Is_Entity_Name
(Name
(Item
))
6621 and then Entity
(Name
(Item
)) = E
6622 and then not Private_Present
(Item
)
6630 end In_Regular_With_Clause
;
6632 -- Start of processing for Remove_Private_With_Clauses
6635 Item
:= First
(Context_Items
(Comp_Unit
));
6636 while Present
(Item
) loop
6637 if Nkind
(Item
) = N_With_Clause
and then Private_Present
(Item
) then
6639 -- If private_with_clause is redundant, remove it from context,
6640 -- as a small optimization to subsequent handling of private_with
6641 -- clauses in other nested packages.
6643 if In_Regular_With_Clause
(Entity
(Name
(Item
))) then
6645 Nxt
: constant Node_Id
:= Next
(Item
);
6651 elsif Limited_Present
(Item
) then
6652 if not Limited_View_Installed
(Item
) then
6653 Remove_Limited_With_Clause
(Item
);
6659 Remove_Unit_From_Visibility
(Entity
(Name
(Item
)));
6660 Set_Context_Installed
(Item
, False);
6668 end Remove_Private_With_Clauses
;
6670 ---------------------------------
6671 -- Remove_Unit_From_Visibility --
6672 ---------------------------------
6674 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
) is
6676 if Debug_Flag_I
then
6677 Write_Str
("remove unit ");
6678 Write_Name
(Chars
(Unit_Name
));
6679 Write_Str
(" from visibility");
6683 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
6684 Set_Is_Potentially_Use_Visible
(Unit_Name
, False);
6685 Set_Is_Immediately_Visible
(Unit_Name
, False);
6687 -- If the unit is a wrapper package, the subprogram instance is
6688 -- what must be removed from visibility.
6689 -- Should we use Related_Instance instead???
6691 if Is_Wrapper_Package
(Unit_Name
) then
6692 Set_Is_Immediately_Visible
(Current_Entity
(Unit_Name
), False);
6694 end Remove_Unit_From_Visibility
;
6709 procedure Unchain
(E
: Entity_Id
) is
6713 Prev
:= Current_Entity
(E
);
6719 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6722 while Present
(Prev
) and then Homonym
(Prev
) /= E
loop
6723 Prev
:= Homonym
(Prev
);
6726 if Present
(Prev
) then
6727 Set_Homonym
(Prev
, Homonym
(E
));
6731 if Debug_Flag_I
then
6732 Write_Str
(" (homonym) unchain ");
6733 Write_Name
(Chars
(E
));