1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Errout
; use Errout
;
31 with Exp_Util
; use Exp_Util
;
32 with Elists
; use Elists
;
33 with Fname
; use Fname
;
34 with Fname
.UF
; use Fname
.UF
;
35 with Freeze
; use Freeze
;
36 with Impunit
; use Impunit
;
37 with Inline
; use Inline
;
39 with Lib
.Load
; use Lib
.Load
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Output
; use Output
;
46 with Par_SCO
; use Par_SCO
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch7
; use Sem_Ch7
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Dist
; use Sem_Dist
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Stand
; use Stand
;
61 with Sinfo
; use Sinfo
;
62 with Sinfo
.CN
; use Sinfo
.CN
;
63 with Sinput
; use Sinput
;
64 with Snames
; use Snames
;
65 with Style
; use Style
;
66 with Stylesw
; use Stylesw
;
67 with Tbuild
; use Tbuild
;
68 with Uname
; use Uname
;
70 package body Sem_Ch10
is
72 -----------------------
73 -- Local Subprograms --
74 -----------------------
76 procedure Analyze_Context
(N
: Node_Id
);
77 -- Analyzes items in the context clause of compilation unit
79 procedure Build_Limited_Views
(N
: Node_Id
);
80 -- Build and decorate the list of shadow entities for a package mentioned
81 -- in a limited_with clause. If the package was not previously analyzed
82 -- then it also performs a basic decoration of the real entities. This is
83 -- required in order to avoid passing non-decorated entities to the
84 -- back-end. Implements Ada 2005 (AI-50217).
86 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
);
87 -- Check whether the source for the body of a compilation unit must be
88 -- included in a standalone library.
90 procedure Check_No_Elab_Code_All
(N
: Node_Id
);
91 -- Carries out possible tests for violation of No_Elab_Code all for withed
92 -- units in the Context_Items of unit N.
94 procedure Check_Private_Child_Unit
(N
: Node_Id
);
95 -- If a with_clause mentions a private child unit, the compilation unit
96 -- must be a member of the same family, as described in 10.1.2.
98 procedure Check_Stub_Level
(N
: Node_Id
);
99 -- Verify that a stub is declared immediately within a compilation unit,
100 -- and not in an inner frame.
102 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
);
103 -- When a child unit appears in a context clause, the implicit withs on
104 -- parents are made explicit, and with clauses are inserted in the context
105 -- clause before the one for the child. If a parent in the with_clause
106 -- is a renaming, the implicit with_clause is on the renaming whose name
107 -- is mentioned in the with_clause, and not on the package it renames.
108 -- N is the compilation unit whose list of context items receives the
109 -- implicit with_clauses.
111 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
);
112 -- Generate cross-reference information for the parents of child units
113 -- and of subunits. N is a defining_program_unit_name, and P_Id is the
114 -- immediate parent scope.
116 function Has_With_Clause
119 Is_Limited
: Boolean := False) return Boolean;
120 -- Determine whether compilation unit C_Unit contains a [limited] with
121 -- clause for package Pack. Use the flag Is_Limited to designate desired
124 procedure Implicit_With_On_Parent
(Child_Unit
: Node_Id
; N
: Node_Id
);
125 -- If the main unit is a child unit, implicit withs are also added for
126 -- all its ancestors.
128 function In_Chain
(E
: Entity_Id
) return Boolean;
129 -- Check that the shadow entity is not already in the homonym chain, for
130 -- example through a limited_with clause in a parent unit.
132 procedure Install_Context_Clauses
(N
: Node_Id
);
133 -- Subsidiary to Install_Context and Install_Parents. Process all with
134 -- and use clauses for current unit and its library unit if any.
136 procedure Install_Limited_Context_Clauses
(N
: Node_Id
);
137 -- Subsidiary to Install_Context. Process only limited with_clauses for
138 -- current unit. Implements Ada 2005 (AI-50217).
140 procedure Install_Limited_Withed_Unit
(N
: Node_Id
);
141 -- Place shadow entities for a limited_with package in the visibility
142 -- structures for the current compilation. Implements Ada 2005 (AI-50217).
144 procedure Install_Withed_Unit
145 (With_Clause
: Node_Id
;
146 Private_With_OK
: Boolean := False);
147 -- If the unit is not a child unit, make unit immediately visible. The
148 -- caller ensures that the unit is not already currently installed. The
149 -- flag Private_With_OK is set true in Install_Private_With_Clauses, which
150 -- is called when compiling the private part of a package, or installing
151 -- the private declarations of a parent unit.
153 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean);
154 -- This procedure establishes the context for the compilation of a child
155 -- unit. If Lib_Unit is a child library spec then the context of the parent
156 -- is installed, and the parent itself made immediately visible, so that
157 -- the child unit is processed in the declarative region of the parent.
158 -- Install_Parents makes a recursive call to itself to ensure that all
159 -- parents are loaded in the nested case. If Lib_Unit is a library body,
160 -- the only effect of Install_Parents is to install the private decls of
161 -- the parents, because the visible parent declarations will have been
162 -- installed as part of the context of the corresponding spec.
164 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
);
165 -- In the compilation of a child unit, a child of any of the ancestor
166 -- units is directly visible if it is visible, because the parent is in
167 -- an enclosing scope. Iterate over context to find child units of U_Name
168 -- or of some ancestor of it.
170 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean;
171 -- When compiling a unit Q descended from some parent unit P, a limited
172 -- with_clause in the context of P that names some other ancestor of Q
173 -- must not be installed because the ancestor is immediately visible.
175 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean;
176 -- Lib_Unit is a library unit which may be a spec or a body. Is_Child_Spec
177 -- returns True if Lib_Unit is a library spec which is a child spec, i.e.
178 -- a library spec that has a parent. If the call to Is_Child_Spec returns
179 -- True, then Parent_Spec (Lib_Unit) is non-Empty and points to the
180 -- compilation unit for the parent spec.
182 -- Lib_Unit can also be a subprogram body that acts as its own spec. If the
183 -- Parent_Spec is non-empty, this is also a child unit.
185 procedure Remove_Context_Clauses
(N
: Node_Id
);
186 -- Subsidiary of previous one. Remove use_ and with_clauses
188 procedure Remove_Limited_With_Clause
(N
: Node_Id
);
189 -- Remove from visibility the shadow entities introduced for a package
190 -- mentioned in a limited_with clause. Implements Ada 2005 (AI-50217).
192 procedure Remove_Parents
(Lib_Unit
: Node_Id
);
193 -- Remove_Parents checks if Lib_Unit is a child spec. If so then the parent
194 -- contexts established by the corresponding call to Install_Parents are
195 -- removed. Remove_Parents contains a recursive call to itself to ensure
196 -- that all parents are removed in the nested case.
198 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
);
199 -- Reset all visibility flags on unit after compiling it, either as a main
200 -- unit or as a unit in the context.
202 procedure Unchain
(E
: Entity_Id
);
203 -- Remove single entity from visibility list
205 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
);
206 -- Common processing for all stubs (subprograms, tasks, packages, and
207 -- protected cases). N is the stub to be analyzed. Once the subunit name
208 -- is established, load and analyze. Nam is the non-overloadable entity
209 -- for which the proper body provides a completion. Subprogram stubs are
210 -- handled differently because they can be declarations.
213 -- A dummy procedure, for debugging use, called just before analyzing the
214 -- main unit (after dealing with any context clauses).
216 --------------------------
217 -- Limited_With_Clauses --
218 --------------------------
220 -- Limited_With clauses are the mechanism chosen for Ada 2005 to support
221 -- mutually recursive types declared in different units. A limited_with
222 -- clause that names package P in the context of unit U makes the types
223 -- declared in the visible part of P available within U, but with the
224 -- restriction that these types can only be used as incomplete types.
225 -- The limited_with clause does not impose a semantic dependence on P,
226 -- and it is possible for two packages to have limited_with_clauses on
227 -- each other without creating an elaboration circularity.
229 -- To support this feature, the analysis of a limited_with clause must
230 -- create an abbreviated view of the package, without performing any
231 -- semantic analysis on it. This "package abstract" contains shadow types
232 -- that are in one-one correspondence with the real types in the package,
233 -- and that have the properties of incomplete types.
235 -- The implementation creates two element lists: one to chain the shadow
236 -- entities, and one to chain the corresponding type entities in the tree
237 -- of the package. Links between corresponding entities in both chains
238 -- allow the compiler to select the proper view of a given type, depending
239 -- on the context. Note that in contrast with the handling of private
240 -- types, the limited view and the non-limited view of a type are treated
241 -- as separate entities, and no entity exchange needs to take place, which
242 -- makes the implementation much simpler than could be feared.
244 ------------------------------
245 -- Analyze_Compilation_Unit --
246 ------------------------------
248 procedure Analyze_Compilation_Unit
(N
: Node_Id
) is
249 Unit_Node
: constant Node_Id
:= Unit
(N
);
250 Lib_Unit
: Node_Id
:= Library_Unit
(N
);
252 Main_Cunit
: constant Node_Id
:= Cunit
(Main_Unit
);
253 Par_Spec_Name
: Unit_Name_Type
;
254 Unum
: Unit_Number_Type
;
256 procedure Check_Redundant_Withs
257 (Context_Items
: List_Id
;
258 Spec_Context_Items
: List_Id
:= No_List
);
259 -- Determine whether the context list of a compilation unit contains
260 -- redundant with clauses. When checking body clauses against spec
261 -- clauses, set Context_Items to the context list of the body and
262 -- Spec_Context_Items to that of the spec. Parent packages are not
263 -- examined for documentation purposes.
265 ---------------------------
266 -- Check_Redundant_Withs --
267 ---------------------------
269 procedure Check_Redundant_Withs
270 (Context_Items
: List_Id
;
271 Spec_Context_Items
: List_Id
:= No_List
)
275 procedure Process_Body_Clauses
276 (Context_List
: List_Id
;
278 Used
: in out Boolean;
279 Used_Type_Or_Elab
: in out Boolean);
280 -- Examine the context clauses of a package body, trying to match the
281 -- name entity of Clause with any list element. If the match occurs
282 -- on a use package clause set Used to True, for a use type clause or
283 -- pragma Elaborate[_All], set Used_Type_Or_Elab to True.
285 procedure Process_Spec_Clauses
286 (Context_List
: List_Id
;
288 Used
: in out Boolean;
289 Withed
: in out Boolean;
290 Exit_On_Self
: Boolean := False);
291 -- Examine the context clauses of a package spec, trying to match
292 -- the name entity of Clause with any list element. If the match
293 -- occurs on a use package clause, set Used to True, for a with
294 -- package clause other than Clause, set Withed to True. Limited
295 -- with clauses, implicitly generated with clauses and withs
296 -- having pragmas Elaborate or Elaborate_All applied to them are
297 -- skipped. Exit_On_Self is used to control the search loop and
298 -- force an exit whenever Clause sees itself in the search.
300 --------------------------
301 -- Process_Body_Clauses --
302 --------------------------
304 procedure Process_Body_Clauses
305 (Context_List
: List_Id
;
307 Used
: in out Boolean;
308 Used_Type_Or_Elab
: in out Boolean)
310 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
316 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean;
317 -- In an expanded name in a use clause, if the prefix is a renamed
318 -- package, the entity is set to the original package as a result,
319 -- when checking whether the package appears in a previous with
320 -- clause, the renaming has to be taken into account, to prevent
321 -- spurious/incorrect warnings. A common case is use of Text_IO.
327 function Same_Unit
(N
: Node_Id
; P
: Entity_Id
) return Boolean is
329 return Entity
(N
) = P
330 or else (Present
(Renamed_Object
(P
))
331 and then Entity
(N
) = Renamed_Object
(P
));
334 -- Start of processing for Process_Body_Clauses
338 Used_Type_Or_Elab
:= False;
340 Cont_Item
:= First
(Context_List
);
341 while Present
(Cont_Item
) loop
343 -- Package use clause
345 if Nkind
(Cont_Item
) = N_Use_Package_Clause
348 -- Search through use clauses
350 Use_Item
:= First
(Names
(Cont_Item
));
351 while Present
(Use_Item
) and then not Used
loop
353 -- Case of a direct use of the one we are looking for
355 if Entity
(Use_Item
) = Nam_Ent
then
358 -- Handle nested case, as in "with P; use P.Q.R"
365 -- Loop through prefixes looking for match
368 while Nkind
(UE
) = N_Expanded_Name
loop
369 if Same_Unit
(Prefix
(UE
), Nam_Ent
) then
384 elsif Nkind
(Cont_Item
) = N_Use_Type_Clause
385 and then not Used_Type_Or_Elab
387 Subt_Mark
:= First
(Subtype_Marks
(Cont_Item
));
388 while Present
(Subt_Mark
)
389 and then not Used_Type_Or_Elab
391 if Same_Unit
(Prefix
(Subt_Mark
), Nam_Ent
) then
392 Used_Type_Or_Elab
:= True;
398 -- Pragma Elaborate or Elaborate_All
400 elsif Nkind
(Cont_Item
) = N_Pragma
402 Nam_In
(Pragma_Name
(Cont_Item
), Name_Elaborate
,
404 and then not Used_Type_Or_Elab
407 First
(Pragma_Argument_Associations
(Cont_Item
));
408 while Present
(Prag_Unit
) and then not Used_Type_Or_Elab
loop
409 if Entity
(Expression
(Prag_Unit
)) = Nam_Ent
then
410 Used_Type_Or_Elab
:= True;
419 end Process_Body_Clauses
;
421 --------------------------
422 -- Process_Spec_Clauses --
423 --------------------------
425 procedure Process_Spec_Clauses
426 (Context_List
: List_Id
;
428 Used
: in out Boolean;
429 Withed
: in out Boolean;
430 Exit_On_Self
: Boolean := False)
432 Nam_Ent
: constant Entity_Id
:= Entity
(Name
(Clause
));
440 Cont_Item
:= First
(Context_List
);
441 while Present
(Cont_Item
) loop
443 -- Stop the search since the context items after Cont_Item have
444 -- already been examined in a previous iteration of the reverse
445 -- loop in Check_Redundant_Withs.
448 and Cont_Item
= Clause
453 -- Package use clause
455 if Nkind
(Cont_Item
) = N_Use_Package_Clause
458 Use_Item
:= First
(Names
(Cont_Item
));
459 while Present
(Use_Item
) and then not Used
loop
460 if Entity
(Use_Item
) = Nam_Ent
then
467 -- Package with clause. Avoid processing self, implicitly
468 -- generated with clauses or limited with clauses. Note that
469 -- we examine with clauses having pragmas Elaborate or
470 -- Elaborate_All applied to them due to cases such as:
474 -- pragma Elaborate (Pack);
476 -- In this case, the second with clause is redundant since
477 -- the pragma applies only to the first "with Pack;".
479 -- Note that we only consider with_clauses that comes from
480 -- source. In the case of renamings used as prefixes of names
481 -- in with_clauses, we generate a with_clause for the prefix,
482 -- which we do not treat as implicit because it is needed for
483 -- visibility analysis, but is also not redundant.
485 elsif Nkind
(Cont_Item
) = N_With_Clause
486 and then not Implicit_With
(Cont_Item
)
487 and then Comes_From_Source
(Cont_Item
)
488 and then not Limited_Present
(Cont_Item
)
489 and then Cont_Item
/= Clause
490 and then Entity
(Name
(Cont_Item
)) = Nam_Ent
497 end Process_Spec_Clauses
;
499 -- Start of processing for Check_Redundant_Withs
502 Clause
:= Last
(Context_Items
);
503 while Present
(Clause
) loop
505 -- Avoid checking implicitly generated with clauses, limited with
506 -- clauses or withs that have pragma Elaborate or Elaborate_All.
508 if Nkind
(Clause
) = N_With_Clause
509 and then not Implicit_With
(Clause
)
510 and then not Limited_Present
(Clause
)
511 and then not Elaborate_Present
(Clause
)
513 -- With_clauses introduced for renamings of parent clauses
514 -- are not marked implicit because they need to be properly
515 -- installed, but they do not come from source and do not
518 and then Comes_From_Source
(Clause
)
520 -- Package body-to-spec check
522 if Present
(Spec_Context_Items
) then
524 Used_In_Body
: Boolean := False;
525 Used_In_Spec
: Boolean := False;
526 Used_Type_Or_Elab
: Boolean := False;
527 Withed_In_Spec
: Boolean := False;
531 (Context_List
=> Spec_Context_Items
,
533 Used
=> Used_In_Spec
,
534 Withed
=> Withed_In_Spec
);
537 (Context_List
=> Context_Items
,
539 Used
=> Used_In_Body
,
540 Used_Type_Or_Elab
=> Used_Type_Or_Elab
);
542 -- "Type Elab" refers to the presence of either a use
543 -- type clause, pragmas Elaborate or Elaborate_All.
545 -- +---------------+---------------------------+------+
546 -- | Spec | Body | Warn |
547 -- +--------+------+--------+------+-----------+------+
548 -- | Withed | Used | Withed | Used | Type Elab | |
549 -- | X | | X | | | X |
550 -- | X | | X | X | | |
551 -- | X | | X | | X | |
552 -- | X | | X | X | X | |
553 -- | X | X | X | | | X |
554 -- | X | X | X | | X | |
555 -- | X | X | X | X | | X |
556 -- | X | X | X | X | X | |
557 -- +--------+------+--------+------+-----------+------+
560 and then not Used_Type_Or_Elab
)
562 ((not Used_In_Spec
and then not Used_In_Body
)
563 or else Used_In_Spec
)
565 Error_Msg_N
-- CODEFIX
566 ("redundant with clause in body??", Clause
);
569 Used_In_Body
:= False;
570 Used_In_Spec
:= False;
571 Used_Type_Or_Elab
:= False;
572 Withed_In_Spec
:= False;
575 -- Standalone package spec or body check
579 Dont_Care
: Boolean := False;
580 Withed
: Boolean := False;
583 -- The mechanism for examining the context clauses of a
584 -- package spec can be applied to package body clauses.
587 (Context_List
=> Context_Items
,
591 Exit_On_Self
=> True);
594 Error_Msg_N
-- CODEFIX
595 ("redundant with clause??", Clause
);
603 end Check_Redundant_Withs
;
605 -- Start of processing for Analyze_Compilation_Unit
608 Process_Compilation_Unit_Pragmas
(N
);
610 -- If the unit is a subunit whose parent has not been analyzed (which
611 -- indicates that the main unit is a subunit, either the current one or
612 -- one of its descendents) then the subunit is compiled as part of the
613 -- analysis of the parent, which we proceed to do. Basically this gets
614 -- handled from the top down and we don't want to do anything at this
615 -- level (i.e. this subunit will be handled on the way down from the
616 -- parent), so at this level we immediately return. If the subunit ends
617 -- up not analyzed, it means that the parent did not contain a stub for
618 -- it, or that there errors were detected in some ancestor.
620 if Nkind
(Unit_Node
) = N_Subunit
and then not Analyzed
(Lib_Unit
) then
621 Semantics
(Lib_Unit
);
623 if not Analyzed
(Proper_Body
(Unit_Node
)) then
624 if Serious_Errors_Detected
> 0 then
625 Error_Msg_N
("subunit not analyzed (errors in parent unit)", N
);
627 Error_Msg_N
("missing stub for subunit", N
);
634 -- Analyze context (this will call Sem recursively for with'ed units) To
635 -- detect circularities among with-clauses that are not caught during
636 -- loading, we set the Context_Pending flag on the current unit. If the
637 -- flag is already set there is a potential circularity. We exclude
638 -- predefined units from this check because they are known to be safe.
639 -- We also exclude package bodies that are present because circularities
640 -- between bodies are harmless (and necessary).
642 if Context_Pending
(N
) then
644 Circularity
: Boolean := True;
647 if Is_Predefined_File_Name
648 (Unit_File_Name
(Get_Source_Unit
(Unit
(N
))))
650 Circularity
:= False;
653 for U
in Main_Unit
+ 1 .. Last_Unit
loop
654 if Nkind
(Unit
(Cunit
(U
))) = N_Package_Body
655 and then not Analyzed
(Cunit
(U
))
657 Circularity
:= False;
664 Error_Msg_N
("circular dependency caused by with_clauses", N
);
666 ("\possibly missing limited_with clause"
667 & " in one of the following", N
);
669 for U
in Main_Unit
.. Last_Unit
loop
670 if Context_Pending
(Cunit
(U
)) then
671 Error_Msg_Unit_1
:= Get_Unit_Name
(Unit
(Cunit
(U
)));
672 Error_Msg_N
("\unit$", N
);
676 raise Unrecoverable_Error
;
680 Set_Context_Pending
(N
);
685 Set_Context_Pending
(N
, False);
687 -- If the unit is a package body, the spec is already loaded and must be
688 -- analyzed first, before we analyze the body.
690 if Nkind
(Unit_Node
) = N_Package_Body
then
692 -- If no Lib_Unit, then there was a serious previous error, so just
693 -- ignore the entire analysis effort
695 if No
(Lib_Unit
) then
696 Check_Error_Detected
;
700 -- Analyze the package spec
702 Semantics
(Lib_Unit
);
704 -- Check for unused with's
706 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
708 -- Verify that the library unit is a package declaration
710 if not Nkind_In
(Unit
(Lib_Unit
), N_Package_Declaration
,
711 N_Generic_Package_Declaration
)
714 ("no legal package declaration for package body", N
);
717 -- Otherwise, the entity in the declaration is visible. Update the
718 -- version to reflect dependence of this body on the spec.
721 Spec_Id
:= Defining_Entity
(Unit
(Lib_Unit
));
722 Set_Is_Immediately_Visible
(Spec_Id
, True);
723 Version_Update
(N
, Lib_Unit
);
725 if Nkind
(Defining_Unit_Name
(Unit_Node
)) =
726 N_Defining_Program_Unit_Name
728 Generate_Parent_References
(Unit_Node
, Scope
(Spec_Id
));
733 -- If the unit is a subprogram body, then we similarly need to analyze
734 -- its spec. However, things are a little simpler in this case, because
735 -- here, this analysis is done mostly for error checking and consistency
736 -- purposes (but not only, e.g. there could be a contract on the spec),
737 -- so there's nothing else to be done.
739 elsif Nkind
(Unit_Node
) = N_Subprogram_Body
then
740 if Acts_As_Spec
(N
) then
742 -- If the subprogram body is a child unit, we must create a
743 -- declaration for it, in order to properly load the parent(s).
744 -- After this, the original unit does not acts as a spec, because
745 -- there is an explicit one. If this unit appears in a context
746 -- clause, then an implicit with on the parent will be added when
747 -- installing the context. If this is the main unit, there is no
748 -- Unit_Table entry for the declaration (it has the unit number
749 -- of the main unit) and code generation is unaffected.
751 Unum
:= Get_Cunit_Unit_Number
(N
);
752 Par_Spec_Name
:= Get_Parent_Spec_Name
(Unit_Name
(Unum
));
754 if Par_Spec_Name
/= No_Unit_Name
then
757 (Load_Name
=> Par_Spec_Name
,
762 if Unum
/= No_Unit
then
764 -- Build subprogram declaration and attach parent unit to it
765 -- This subprogram declaration does not come from source,
766 -- Nevertheless the backend must generate debugging info for
767 -- it, and this must be indicated explicitly. We also mark
768 -- the body entity as a child unit now, to prevent a
769 -- cascaded error if the spec entity cannot be entered
770 -- in its scope. Finally we create a Units table entry for
771 -- the subprogram declaration, to maintain a one-to-one
772 -- correspondence with compilation unit nodes. This is
773 -- critical for the tree traversals performed by CodePeer.
776 Loc
: constant Source_Ptr
:= Sloc
(N
);
777 SCS
: constant Boolean :=
778 Get_Comes_From_Source_Default
;
781 Set_Comes_From_Source_Default
(False);
783 -- Checks for redundant USE TYPE clauses have a special
784 -- exception for the synthetic spec we create here. This
785 -- special case relies on the two compilation units
786 -- sharing the same context clause.
788 -- Note: We used to do a shallow copy (New_Copy_List),
789 -- which defeated those checks and also created malformed
790 -- trees (subtype mark shared by two distinct
791 -- N_Use_Type_Clause nodes) which crashed the compiler.
794 Make_Compilation_Unit
(Loc
,
795 Context_Items
=> Context_Items
(N
),
797 Make_Subprogram_Declaration
(Sloc
(N
),
800 (Specification
(Unit_Node
))),
802 Make_Compilation_Unit_Aux
(Loc
));
804 Set_Library_Unit
(N
, Lib_Unit
);
805 Set_Parent_Spec
(Unit
(Lib_Unit
), Cunit
(Unum
));
806 Make_Child_Decl_Unit
(N
);
807 Semantics
(Lib_Unit
);
809 -- Now that a separate declaration exists, the body
810 -- of the child unit does not act as spec any longer.
812 Set_Acts_As_Spec
(N
, False);
813 Set_Is_Child_Unit
(Defining_Entity
(Unit_Node
));
814 Set_Debug_Info_Needed
(Defining_Entity
(Unit
(Lib_Unit
)));
815 Set_Comes_From_Source_Default
(SCS
);
820 -- Here for subprogram with separate declaration
823 Semantics
(Lib_Unit
);
824 Check_Unused_Withs
(Get_Cunit_Unit_Number
(Lib_Unit
));
825 Version_Update
(N
, Lib_Unit
);
828 -- If this is a child unit, generate references to the parents
830 if Nkind
(Defining_Unit_Name
(Specification
(Unit_Node
))) =
831 N_Defining_Program_Unit_Name
833 Generate_Parent_References
834 (Specification
(Unit_Node
),
835 Scope
(Defining_Entity
(Unit
(Lib_Unit
))));
839 -- If it is a child unit, the parent must be elaborated first and we
840 -- update version, since we are dependent on our parent.
842 if Is_Child_Spec
(Unit_Node
) then
844 -- The analysis of the parent is done with style checks off
847 Save_Style_Check
: constant Boolean := Style_Check
;
850 if not GNAT_Mode
then
851 Style_Check
:= False;
854 Semantics
(Parent_Spec
(Unit_Node
));
855 Version_Update
(N
, Parent_Spec
(Unit_Node
));
857 -- Restore style check settings
859 Style_Check
:= Save_Style_Check
;
863 -- With the analysis done, install the context. Note that we can't
864 -- install the context from the with clauses as we analyze them, because
865 -- each with clause must be analyzed in a clean visibility context, so
866 -- we have to wait and install them all at once.
870 if Is_Child_Spec
(Unit_Node
) then
872 -- Set the entities of all parents in the program_unit_name
874 Generate_Parent_References
875 (Unit_Node
, Get_Parent_Entity
(Unit
(Parent_Spec
(Unit_Node
))));
878 -- All components of the context: with-clauses, library unit, ancestors
879 -- if any, (and their context) are analyzed and installed.
881 -- Call special debug routine sm if this is the main unit
883 if Current_Sem_Unit
= Main_Unit
then
887 -- Now analyze the unit (package, subprogram spec, body) itself
891 if Warn_On_Redundant_Constructs
then
892 Check_Redundant_Withs
(Context_Items
(N
));
894 if Nkind
(Unit_Node
) = N_Package_Body
then
895 Check_Redundant_Withs
896 (Context_Items
=> Context_Items
(N
),
897 Spec_Context_Items
=> Context_Items
(Lib_Unit
));
901 -- The above call might have made Unit_Node an N_Subprogram_Body from
902 -- something else, so propagate any Acts_As_Spec flag.
904 if Nkind
(Unit_Node
) = N_Subprogram_Body
905 and then Acts_As_Spec
(Unit_Node
)
907 Set_Acts_As_Spec
(N
);
910 -- Register predefined units in Rtsfind
913 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Sloc
(N
));
915 if Is_Predefined_File_Name
(Unit_File_Name
(Unum
)) then
916 Set_RTU_Loaded
(Unit_Node
);
920 -- Treat compilation unit pragmas that appear after the library unit
922 if Present
(Pragmas_After
(Aux_Decls_Node
(N
))) then
924 Prag_Node
: Node_Id
:= First
(Pragmas_After
(Aux_Decls_Node
(N
)));
926 while Present
(Prag_Node
) loop
933 -- Generate distribution stubs if requested and no error
936 and then (Distribution_Stub_Mode
= Generate_Receiver_Stub_Body
938 Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
939 and then not Fatal_Error
(Main_Unit
)
941 if Is_RCI_Pkg_Spec_Or_Body
(N
) then
943 -- Regular RCI package
945 Add_Stub_Constructs
(N
);
947 elsif (Nkind
(Unit_Node
) = N_Package_Declaration
948 and then Is_Shared_Passive
(Defining_Entity
949 (Specification
(Unit_Node
))))
950 or else (Nkind
(Unit_Node
) = N_Package_Body
952 Is_Shared_Passive
(Corresponding_Spec
(Unit_Node
)))
954 -- Shared passive package
956 Add_Stub_Constructs
(N
);
958 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
960 Is_Remote_Call_Interface
961 (Defining_Entity
(Specification
(Instance_Spec
(Unit_Node
))))
963 -- Instantiation of a RCI generic package
965 Add_Stub_Constructs
(N
);
969 -- Remove unit from visibility, so that environment is clean for the
970 -- next compilation, which is either the main unit or some other unit
973 if Nkind_In
(Unit_Node
, N_Package_Declaration
,
974 N_Package_Renaming_Declaration
,
975 N_Subprogram_Declaration
)
976 or else Nkind
(Unit_Node
) in N_Generic_Declaration
977 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
978 and then Acts_As_Spec
(Unit_Node
))
980 Remove_Unit_From_Visibility
(Defining_Entity
(Unit_Node
));
982 -- If the unit is an instantiation whose body will be elaborated for
983 -- inlining purposes, use the proper entity of the instance. The entity
984 -- may be missing if the instantiation was illegal.
986 elsif Nkind
(Unit_Node
) = N_Package_Instantiation
987 and then not Error_Posted
(Unit_Node
)
988 and then Present
(Instance_Spec
(Unit_Node
))
990 Remove_Unit_From_Visibility
991 (Defining_Entity
(Instance_Spec
(Unit_Node
)));
993 elsif Nkind
(Unit_Node
) = N_Package_Body
994 or else (Nkind
(Unit_Node
) = N_Subprogram_Body
995 and then not Acts_As_Spec
(Unit_Node
))
997 -- Bodies that are not the main unit are compiled if they are generic
998 -- or contain generic or inlined units. Their analysis brings in the
999 -- context of the corresponding spec (unit declaration) which must be
1000 -- removed as well, to return the compilation environment to its
1003 Remove_Context
(Lib_Unit
);
1004 Set_Is_Immediately_Visible
(Defining_Entity
(Unit
(Lib_Unit
)), False);
1007 -- Last step is to deinstall the context we just installed as well as
1008 -- the unit just compiled.
1012 -- If this is the main unit and we are generating code, we must check
1013 -- that all generic units in the context have a body if they need it,
1014 -- even if they have not been instantiated. In the absence of .ali files
1015 -- for generic units, we must force the load of the body, just to
1016 -- produce the proper error if the body is absent. We skip this
1017 -- verification if the main unit itself is generic.
1019 if Get_Cunit_Unit_Number
(N
) = Main_Unit
1020 and then Operating_Mode
= Generate_Code
1021 and then Expander_Active
1023 -- Check whether the source for the body of the unit must be included
1024 -- in a standalone library.
1026 Check_Body_Needed_For_SAL
(Cunit_Entity
(Main_Unit
));
1028 -- Indicate that the main unit is now analyzed, to catch possible
1029 -- circularities between it and generic bodies. Remove main unit from
1030 -- visibility. This might seem superfluous, but the main unit must
1031 -- not be visible in the generic body expansions that follow.
1033 Set_Analyzed
(N
, True);
1034 Set_Is_Immediately_Visible
(Cunit_Entity
(Main_Unit
), False);
1039 Un
: Unit_Number_Type
;
1041 Save_Style_Check
: constant Boolean := Style_Check
;
1044 Item
:= First
(Context_Items
(N
));
1045 while Present
(Item
) loop
1047 -- Check for explicit with clause
1049 if Nkind
(Item
) = N_With_Clause
1050 and then not Implicit_With
(Item
)
1052 -- Ada 2005 (AI-50217): Ignore limited-withed units
1054 and then not Limited_Present
(Item
)
1056 Nam
:= Entity
(Name
(Item
));
1058 -- Compile generic subprogram, unless it is intrinsic or
1059 -- imported so no body is required, or generic package body
1060 -- if the package spec requires a body.
1062 if (Is_Generic_Subprogram
(Nam
)
1063 and then not Is_Intrinsic_Subprogram
(Nam
)
1064 and then not Is_Imported
(Nam
))
1065 or else (Ekind
(Nam
) = E_Generic_Package
1066 and then Unit_Requires_Body
(Nam
))
1068 Style_Check
:= False;
1070 if Present
(Renamed_Object
(Nam
)) then
1073 (Load_Name
=> Get_Body_Name
1075 (Unit_Declaration_Node
1076 (Renamed_Object
(Nam
)))),
1084 (Load_Name
=> Get_Body_Name
1085 (Get_Unit_Name
(Item
)),
1092 if Un
= No_Unit
then
1094 ("body of generic unit& not found", Item
, Nam
);
1097 elsif not Analyzed
(Cunit
(Un
))
1098 and then Un
/= Main_Unit
1099 and then not Fatal_Error
(Un
)
1101 Style_Check
:= False;
1102 Semantics
(Cunit
(Un
));
1110 -- Restore style checks settings
1112 Style_Check
:= Save_Style_Check
;
1116 -- Deal with creating elaboration counter if needed. We create an
1117 -- elaboration counter only for units that come from source since
1118 -- units manufactured by the compiler never need elab checks.
1120 if Comes_From_Source
(N
)
1121 and then Nkind_In
(Unit_Node
, N_Package_Declaration
,
1122 N_Generic_Package_Declaration
,
1123 N_Subprogram_Declaration
,
1124 N_Generic_Subprogram_Declaration
)
1127 Loc
: constant Source_Ptr
:= Sloc
(N
);
1128 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
1131 Spec_Id
:= Defining_Entity
(Unit_Node
);
1132 Generate_Definition
(Spec_Id
);
1134 -- See if an elaboration entity is required for possible access
1135 -- before elaboration checking. Note that we must allow for this
1136 -- even if -gnatE is not set, since a client may be compiled in
1137 -- -gnatE mode and reference the entity.
1139 -- These entities are also used by the binder to prevent multiple
1140 -- attempts to execute the elaboration code for the library case
1141 -- where the elaboration routine might otherwise be called more
1144 -- Case of units which do not require elaboration checks
1147 -- Pure units do not need checks
1151 -- Preelaborated units do not need checks
1153 or else Is_Preelaborated
(Spec_Id
)
1155 -- No checks needed if pragma Elaborate_Body present
1157 or else Has_Pragma_Elaborate_Body
(Spec_Id
)
1159 -- No checks needed if unit does not require a body
1161 or else not Unit_Requires_Body
(Spec_Id
)
1163 -- No checks needed for predefined files
1165 or else Is_Predefined_File_Name
(Unit_File_Name
(Unum
))
1167 -- No checks required if no separate spec
1169 or else Acts_As_Spec
(N
)
1171 -- This is a case where we only need the entity for
1172 -- checking to prevent multiple elaboration checks.
1174 Set_Elaboration_Entity_Required
(Spec_Id
, False);
1176 -- Case of elaboration entity is required for access before
1177 -- elaboration checking (so certainly we must build it).
1180 Set_Elaboration_Entity_Required
(Spec_Id
, True);
1183 Build_Elaboration_Entity
(N
, Spec_Id
);
1187 -- Freeze the compilation unit entity. This for sure is needed because
1188 -- of some warnings that can be output (see Freeze_Subprogram), but may
1189 -- in general be required. If freezing actions result, place them in the
1190 -- compilation unit actions list, and analyze them.
1193 L
: constant List_Id
:=
1194 Freeze_Entity
(Cunit_Entity
(Current_Sem_Unit
), N
);
1196 while Is_Non_Empty_List
(L
) loop
1197 Insert_Library_Level_Action
(Remove_Head
(L
));
1203 -- Call Check_Package_Body so that a body containing subprograms with
1204 -- Inline_Always can be made available for front end inlining.
1206 if Nkind
(Unit_Node
) = N_Package_Declaration
1207 and then Get_Cunit_Unit_Number
(N
) /= Main_Unit
1209 -- We don't need to do this if the Expander is not active, since there
1210 -- is no code to inline.
1212 and then Expander_Active
1215 Save_Style_Check
: constant Boolean := Style_Check
;
1216 Save_Warning
: constant Warning_Mode_Type
:= Warning_Mode
;
1217 Options
: Style_Check_Options
;
1220 Save_Style_Check_Options
(Options
);
1221 Reset_Style_Check_Options
;
1222 Opt
.Warning_Mode
:= Suppress
;
1224 Check_Package_Body_For_Inlining
(N
, Defining_Entity
(Unit_Node
));
1226 Reset_Style_Check_Options
;
1227 Set_Style_Check_Options
(Options
);
1228 Style_Check
:= Save_Style_Check
;
1229 Warning_Mode
:= Save_Warning
;
1233 -- If we are generating obsolescent warnings, then here is where we
1234 -- generate them for the with'ed items. The reason for this special
1235 -- processing is that the normal mechanism of generating the warnings
1236 -- for referenced entities does not work for context clause references.
1237 -- That's because when we first analyze the context, it is too early to
1238 -- know if the with'ing unit is itself obsolescent (which suppresses
1242 and then Warn_On_Obsolescent_Feature
1243 and then Nkind
(Unit_Node
) not in N_Generic_Instantiation
1245 -- Push current compilation unit as scope, so that the test for
1246 -- being within an obsolescent unit will work correctly. The check
1247 -- is not performed within an instantiation, because the warning
1248 -- will have been emitted in the corresponding generic unit.
1250 Push_Scope
(Defining_Entity
(Unit_Node
));
1252 -- Loop through context items to deal with with clauses
1260 Item
:= First
(Context_Items
(N
));
1261 while Present
(Item
) loop
1262 if Nkind
(Item
) = N_With_Clause
1264 -- Suppress this check in limited-withed units. Further work
1265 -- needed here if we decide to incorporate this check on
1266 -- limited-withed units.
1268 and then not Limited_Present
(Item
)
1271 Ent
:= Entity
(Nam
);
1273 if Is_Obsolescent
(Ent
) then
1274 Output_Obsolescent_Entity_Warnings
(Nam
, Ent
);
1282 -- Remove temporary install of current unit as scope
1287 -- If No_Elaboration_Code_All was encountered, this is where we do the
1288 -- transitive test of with'ed units to make sure they have the aspect.
1289 -- This is delayed till the end of analyzing the compilation unit to
1290 -- ensure that the pragma/aspect, if present, has been analyzed.
1292 Check_No_Elab_Code_All
(N
);
1293 end Analyze_Compilation_Unit
;
1295 ---------------------
1296 -- Analyze_Context --
1297 ---------------------
1299 procedure Analyze_Context
(N
: Node_Id
) is
1300 Ukind
: constant Node_Kind
:= Nkind
(Unit
(N
));
1304 -- First process all configuration pragmas at the start of the context
1305 -- items. Strictly these are not part of the context clause, but that
1306 -- is where the parser puts them. In any case for sure we must analyze
1307 -- these before analyzing the actual context items, since they can have
1308 -- an effect on that analysis (e.g. pragma Ada_2005 may allow a unit to
1309 -- be with'ed as a result of changing categorizations in Ada 2005).
1311 Item
:= First
(Context_Items
(N
));
1312 while Present
(Item
)
1313 and then Nkind
(Item
) = N_Pragma
1314 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
1320 -- This is the point at which we capture the configuration settings
1321 -- for the unit. At the moment only the Optimize_Alignment setting
1322 -- needs to be captured. Probably more later ???
1324 if Optimize_Alignment_Local
then
1325 Set_OA_Setting
(Current_Sem_Unit
, 'L');
1327 Set_OA_Setting
(Current_Sem_Unit
, Optimize_Alignment
);
1330 -- Loop through actual context items. This is done in two passes:
1332 -- a) The first pass analyzes non-limited with-clauses and also any
1333 -- configuration pragmas (we need to get the latter analyzed right
1334 -- away, since they can affect processing of subsequent items).
1336 -- b) The second pass analyzes limited_with clauses (Ada 2005: AI-50217)
1338 while Present
(Item
) loop
1340 -- For with clause, analyze the with clause, and then update the
1341 -- version, since we are dependent on a unit that we with.
1343 if Nkind
(Item
) = N_With_Clause
1344 and then not Limited_Present
(Item
)
1346 -- Skip analyzing with clause if no unit, nothing to do (this
1347 -- happens for a with that references a non-existent unit).
1349 if Present
(Library_Unit
(Item
)) then
1351 -- Skip analyzing with clause if this is a with_clause for
1352 -- the main unit, which happens if a subunit has a useless
1353 -- with_clause on its parent.
1355 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
) then
1358 -- Here for the case of a useless with for the main unit
1361 Set_Entity
(Name
(Item
), Cunit_Entity
(Current_Sem_Unit
));
1365 -- Do version update (skipped for implicit with)
1367 if not Implicit_With
(Item
) then
1368 Version_Update
(N
, Library_Unit
(Item
));
1371 -- Skip pragmas. Configuration pragmas at the start were handled in
1372 -- the loop above, and remaining pragmas are not processed until we
1373 -- actually install the context (see Install_Context). We delay the
1374 -- analysis of these pragmas to make sure that we have installed all
1375 -- the implicit with's on parent units.
1377 -- Skip use clauses at this stage, since we don't want to do any
1378 -- installing of potentially use-visible entities until we
1379 -- actually install the complete context (in Install_Context).
1380 -- Otherwise things can get installed in the wrong context.
1389 -- Second pass: examine all limited_with clauses. All other context
1390 -- items are ignored in this pass.
1392 Item
:= First
(Context_Items
(N
));
1393 while Present
(Item
) loop
1394 if Nkind
(Item
) = N_With_Clause
1395 and then Limited_Present
(Item
)
1397 -- No need to check errors on implicitly generated limited-with
1400 if not Implicit_With
(Item
) then
1402 -- Verify that the illegal contexts given in 10.1.2 (18/2) are
1403 -- properly rejected, including renaming declarations.
1405 if not Nkind_In
(Ukind
, N_Package_Declaration
,
1406 N_Subprogram_Declaration
)
1407 and then Ukind
not in N_Generic_Declaration
1408 and then Ukind
not in N_Generic_Instantiation
1410 Error_Msg_N
("limited with_clause not allowed here", Item
);
1412 -- Check wrong use of a limited with clause applied to the
1413 -- compilation unit containing the limited-with clause.
1415 -- limited with P.Q;
1416 -- package P.Q is ...
1418 elsif Unit
(Library_Unit
(Item
)) = Unit
(N
) then
1419 Error_Msg_N
("wrong use of limited-with clause", Item
);
1421 -- Check wrong use of limited-with clause applied to some
1422 -- immediate ancestor.
1424 elsif Is_Child_Spec
(Unit
(N
)) then
1426 Lib_U
: constant Entity_Id
:= Unit
(Library_Unit
(Item
));
1430 P
:= Parent_Spec
(Unit
(N
));
1432 if Unit
(P
) = Lib_U
then
1433 Error_Msg_N
("limited with_clause cannot "
1434 & "name ancestor", Item
);
1438 exit when not Is_Child_Spec
(Unit
(P
));
1439 P
:= Parent_Spec
(Unit
(P
));
1444 -- Check if the limited-withed unit is already visible through
1445 -- some context clause of the current compilation unit or some
1446 -- ancestor of the current compilation unit.
1449 Lim_Unit_Name
: constant Node_Id
:= Name
(Item
);
1450 Comp_Unit
: Node_Id
;
1452 Unit_Name
: Node_Id
;
1457 It
:= First
(Context_Items
(Comp_Unit
));
1458 while Present
(It
) loop
1460 and then Nkind
(It
) = N_With_Clause
1461 and then not Limited_Present
(It
)
1463 Nkind_In
(Unit
(Library_Unit
(It
)),
1464 N_Package_Declaration
,
1465 N_Package_Renaming_Declaration
)
1467 if Nkind
(Unit
(Library_Unit
(It
))) =
1468 N_Package_Declaration
1470 Unit_Name
:= Name
(It
);
1472 Unit_Name
:= Name
(Unit
(Library_Unit
(It
)));
1475 -- Check if the named package (or some ancestor)
1476 -- leaves visible the full-view of the unit given
1477 -- in the limited-with clause
1480 if Designate_Same_Unit
(Lim_Unit_Name
,
1483 Error_Msg_Sloc
:= Sloc
(It
);
1485 ("simultaneous visibility of limited "
1486 & "and unlimited views not allowed",
1489 ("\unlimited view visible through "
1490 & "context clause #",
1494 elsif Nkind
(Unit_Name
) = N_Identifier
then
1498 Unit_Name
:= Prefix
(Unit_Name
);
1505 exit when not Is_Child_Spec
(Unit
(Comp_Unit
));
1507 Comp_Unit
:= Parent_Spec
(Unit
(Comp_Unit
));
1512 -- Skip analyzing with clause if no unit, see above
1514 if Present
(Library_Unit
(Item
)) then
1518 -- A limited_with does not impose an elaboration order, but
1519 -- there is a semantic dependency for recompilation purposes.
1521 if not Implicit_With
(Item
) then
1522 Version_Update
(N
, Library_Unit
(Item
));
1525 -- Pragmas and use clauses and with clauses other than limited
1526 -- with's are ignored in this pass through the context items.
1534 end Analyze_Context
;
1536 -------------------------------
1537 -- Analyze_Package_Body_Stub --
1538 -------------------------------
1540 procedure Analyze_Package_Body_Stub
(N
: Node_Id
) is
1541 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1543 Opts
: Config_Switches_Type
;
1546 -- The package declaration must be in the current declarative part
1548 Check_Stub_Level
(N
);
1549 Nam
:= Current_Entity_In_Scope
(Id
);
1551 if No
(Nam
) or else not Is_Package_Or_Generic_Package
(Nam
) then
1552 Error_Msg_N
("missing specification for package stub", N
);
1554 elsif Has_Completion
(Nam
)
1555 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(Nam
)))
1557 Error_Msg_N
("duplicate or redundant stub for package", N
);
1560 -- Retain and restore the configuration options of the enclosing
1561 -- context as the proper body may introduce a set of its own.
1563 Save_Opt_Config_Switches
(Opts
);
1565 -- Indicate that the body of the package exists. If we are doing
1566 -- only semantic analysis, the stub stands for the body. If we are
1567 -- generating code, the existence of the body will be confirmed
1568 -- when we load the proper body.
1570 Set_Has_Completion
(Nam
);
1571 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1572 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1573 Generate_Reference
(Nam
, Id
, 'b');
1574 Analyze_Proper_Body
(N
, Nam
);
1576 Restore_Opt_Config_Switches
(Opts
);
1578 end Analyze_Package_Body_Stub
;
1580 -------------------------
1581 -- Analyze_Proper_Body --
1582 -------------------------
1584 procedure Analyze_Proper_Body
(N
: Node_Id
; Nam
: Entity_Id
) is
1585 Subunit_Name
: constant Unit_Name_Type
:= Get_Unit_Name
(N
);
1587 procedure Optional_Subunit
;
1588 -- This procedure is called when the main unit is a stub, or when we
1589 -- are not generating code. In such a case, we analyze the subunit if
1590 -- present, which is user-friendly and in fact required for ASIS, but we
1591 -- don't complain if the subunit is missing. In GNATprove_Mode, we issue
1592 -- an error to avoid formal verification of a partial unit.
1594 ----------------------
1595 -- Optional_Subunit --
1596 ----------------------
1598 procedure Optional_Subunit
is
1599 Comp_Unit
: Node_Id
;
1600 Unum
: Unit_Number_Type
;
1603 -- Try to load subunit, but ignore any errors that occur during the
1604 -- loading of the subunit, by using the special feature in Errout to
1605 -- ignore all errors. Note that Fatal_Error will still be set, so we
1606 -- will be able to check for this case below.
1608 if not (ASIS_Mode
or GNATprove_Mode
) then
1609 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
1614 (Load_Name
=> Subunit_Name
,
1615 Required
=> GNATprove_Mode
,
1619 if not (ASIS_Mode
or GNATprove_Mode
) then
1620 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
1623 -- All done if we successfully loaded the subunit
1626 and then (not Fatal_Error
(Unum
) or else Try_Semantics
)
1628 Comp_Unit
:= Cunit
(Unum
);
1630 -- If the file was empty or seriously mangled, the unit itself may
1633 if No
(Unit
(Comp_Unit
)) then
1635 ("subunit does not contain expected proper body", N
);
1637 elsif Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1639 ("expected SEPARATE subunit, found child unit",
1640 Cunit_Entity
(Unum
));
1642 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1643 Analyze_Subunit
(Comp_Unit
);
1644 Set_Library_Unit
(N
, Comp_Unit
);
1645 Set_Corresponding_Body
(N
, Defining_Entity
(Unit
(Comp_Unit
)));
1648 elsif Unum
= No_Unit
1649 and then Present
(Nam
)
1651 if Is_Protected_Type
(Nam
) then
1652 Set_Corresponding_Body
(Parent
(Nam
), Defining_Identifier
(N
));
1654 Set_Corresponding_Body
(
1655 Unit_Declaration_Node
(Nam
), Defining_Identifier
(N
));
1658 end Optional_Subunit
;
1662 Comp_Unit
: Node_Id
;
1663 Unum
: Unit_Number_Type
;
1665 -- Start of processing for Analyze_Proper_Body
1668 -- If the subunit is already loaded, it means that the main unit is a
1669 -- subunit, and that the current unit is one of its parents which was
1670 -- being analyzed to provide the needed context for the analysis of the
1671 -- subunit. In this case we analyze the subunit and continue with the
1672 -- parent, without looking at subsequent subunits.
1674 if Is_Loaded
(Subunit_Name
) then
1676 -- If the proper body is already linked to the stub node, the stub is
1677 -- in a generic unit and just needs analyzing.
1679 if Present
(Library_Unit
(N
)) then
1680 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1682 -- If the subunit has severe errors, the spec of the enclosing
1683 -- body may not be available, in which case do not try analysis.
1685 if Serious_Errors_Detected
> 0
1686 and then No
(Library_Unit
(Library_Unit
(N
)))
1691 Analyze_Subunit
(Library_Unit
(N
));
1693 -- Otherwise we must load the subunit and link to it
1696 -- Load the subunit, this must work, since we originally loaded
1697 -- the subunit earlier on. So this will not really load it, just
1698 -- give access to it.
1702 (Load_Name
=> Subunit_Name
,
1707 -- And analyze the subunit in the parent context (note that we
1708 -- do not call Semantics, since that would remove the parent
1709 -- context). Because of this, we have to manually reset the
1710 -- compiler state to Analyzing since it got destroyed by Load.
1712 if Unum
/= No_Unit
then
1713 Compiler_State
:= Analyzing
;
1715 -- Check that the proper body is a subunit and not a child
1716 -- unit. If the unit was previously loaded, the error will
1717 -- have been emitted when copying the generic node, so we
1718 -- just return to avoid cascaded errors.
1720 if Nkind
(Unit
(Cunit
(Unum
))) /= N_Subunit
then
1724 Set_Corresponding_Stub
(Unit
(Cunit
(Unum
)), N
);
1725 Analyze_Subunit
(Cunit
(Unum
));
1726 Set_Library_Unit
(N
, Cunit
(Unum
));
1730 -- If the main unit is a subunit, then we are just performing semantic
1731 -- analysis on that subunit, and any other subunits of any parent unit
1732 -- should be ignored, except that if we are building trees for ASIS
1733 -- usage we want to annotate the stub properly. If the main unit is
1734 -- itself a subunit, another subunit is irrelevant unless it is a
1735 -- subunit of the current one, that is to say appears in the current
1738 elsif Nkind
(Unit
(Cunit
(Main_Unit
))) = N_Subunit
1739 and then Subunit_Name
/= Unit_Name
(Main_Unit
)
1743 PB
: constant Node_Id
:= Proper_Body
(Unit
(Cunit
(Main_Unit
)));
1745 if Nkind_In
(PB
, N_Package_Body
, N_Subprogram_Body
)
1746 and then List_Containing
(N
) = Declarations
(PB
)
1753 -- But before we return, set the flag for unloaded subunits. This
1754 -- will suppress junk warnings of variables in the same declarative
1755 -- part (or a higher level one) that are in danger of looking unused
1756 -- when in fact there might be a declaration in the subunit that we
1757 -- do not intend to load.
1759 Unloaded_Subunits
:= True;
1762 -- If the subunit is not already loaded, and we are generating code,
1763 -- then this is the case where compilation started from the parent, and
1764 -- we are generating code for an entire subunit tree. In that case we
1765 -- definitely need to load the subunit.
1767 -- In order to continue the analysis with the rest of the parent,
1768 -- and other subunits, we load the unit without requiring its
1769 -- presence, and emit a warning if not found, rather than terminating
1770 -- the compilation abruptly, as for other missing file problems.
1772 elsif Original_Operating_Mode
= Generate_Code
then
1774 -- If the proper body is already linked to the stub node, the stub is
1775 -- in a generic unit and just needs analyzing.
1777 -- We update the version. Although we are not strictly technically
1778 -- semantically dependent on the subunit, given our approach of macro
1779 -- substitution of subunits, it makes sense to include it in the
1780 -- version identification.
1782 if Present
(Library_Unit
(N
)) then
1783 Set_Corresponding_Stub
(Unit
(Library_Unit
(N
)), N
);
1784 Analyze_Subunit
(Library_Unit
(N
));
1785 Version_Update
(Cunit
(Main_Unit
), Library_Unit
(N
));
1787 -- Otherwise we must load the subunit and link to it
1790 -- Make sure that, if the subunit is preprocessed and -gnateG is
1791 -- specified, the preprocessed file will be written.
1793 Lib
.Analysing_Subunit_Of_Main
:= True;
1796 (Load_Name
=> Subunit_Name
,
1800 Lib
.Analysing_Subunit_Of_Main
:= False;
1802 -- Give message if we did not get the unit Emit warning even if
1803 -- missing subunit is not within main unit, to simplify debugging.
1805 if Original_Operating_Mode
= Generate_Code
1806 and then Unum
= No_Unit
1808 Error_Msg_Unit_1
:= Subunit_Name
;
1810 Get_File_Name
(Subunit_Name
, Subunit
=> True);
1812 ("subunit$$ in file{ not found??!!", N
);
1813 Subunits_Missing
:= True;
1816 -- Load_Unit may reset Compiler_State, since it may have been
1817 -- necessary to parse an additional units, so we make sure that
1818 -- we reset it to the Analyzing state.
1820 Compiler_State
:= Analyzing
;
1822 if Unum
/= No_Unit
then
1823 if Debug_Flag_L
then
1824 Write_Str
("*** Loaded subunit from stub. Analyze");
1828 Comp_Unit
:= Cunit
(Unum
);
1830 -- Check for child unit instead of subunit
1832 if Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
1834 ("expected SEPARATE subunit, found child unit",
1835 Cunit_Entity
(Unum
));
1837 -- OK, we have a subunit
1840 Set_Corresponding_Stub
(Unit
(Comp_Unit
), N
);
1841 Set_Library_Unit
(N
, Comp_Unit
);
1843 -- We update the version. Although we are not technically
1844 -- semantically dependent on the subunit, given our approach
1845 -- of macro substitution of subunits, it makes sense to
1846 -- include it in the version identification.
1848 Version_Update
(Cunit
(Main_Unit
), Comp_Unit
);
1850 -- Collect SCO information for loaded subunit if we are in
1855 In_Extended_Main_Source_Unit
1856 (Cunit_Entity
(Current_Sem_Unit
))
1861 -- Analyze the unit if semantics active
1863 if not Fatal_Error
(Unum
) or else Try_Semantics
then
1864 Analyze_Subunit
(Comp_Unit
);
1870 -- The remaining case is when the subunit is not already loaded and we
1871 -- are not generating code. In this case we are just performing semantic
1872 -- analysis on the parent, and we are not interested in the subunit. For
1873 -- subprograms, analyze the stub as a body. For other entities the stub
1874 -- has already been marked as completed.
1879 end Analyze_Proper_Body
;
1881 ----------------------------------
1882 -- Analyze_Protected_Body_Stub --
1883 ----------------------------------
1885 procedure Analyze_Protected_Body_Stub
(N
: Node_Id
) is
1886 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
1889 Check_Stub_Level
(N
);
1891 -- First occurrence of name may have been as an incomplete type
1893 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
1894 Nam
:= Full_View
(Nam
);
1897 if No
(Nam
) or else not Is_Protected_Type
(Etype
(Nam
)) then
1898 Error_Msg_N
("missing specification for Protected body", N
);
1901 -- Currently there are no language-defined aspects that can apply to
1902 -- a protected body stub. Issue an error and remove the aspects to
1903 -- prevent cascaded errors.
1905 if Has_Aspects
(N
) then
1907 ("aspects on protected bodies are not allowed",
1908 First
(Aspect_Specifications
(N
)));
1912 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
1913 Set_Has_Completion
(Etype
(Nam
));
1914 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
1915 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
1916 Analyze_Proper_Body
(N
, Etype
(Nam
));
1918 end Analyze_Protected_Body_Stub
;
1920 -------------------------------------------
1921 -- Analyze_Subprogram_Body_Stub_Contract --
1922 -------------------------------------------
1924 procedure Analyze_Subprogram_Body_Stub_Contract
(Stub_Id
: Entity_Id
) is
1925 Stub_Decl
: constant Node_Id
:= Parent
(Parent
(Stub_Id
));
1926 Spec_Id
: constant Entity_Id
:= Corresponding_Spec_Of_Stub
(Stub_Decl
);
1929 -- A subprogram body stub may act as its own spec or as the completion
1930 -- of a previous declaration. Depending on the context, the contract of
1931 -- the stub may contain two sets of pragmas.
1933 -- The stub is a completion, the applicable pragmas are:
1941 if Present
(Spec_Id
) then
1942 Analyze_Subprogram_Body_Contract
(Stub_Id
);
1944 -- The stub acts as its own spec, the applicable pragmas are:
1949 Analyze_Subprogram_Contract
(Stub_Id
);
1951 end Analyze_Subprogram_Body_Stub_Contract
;
1953 ----------------------------------
1954 -- Analyze_Subprogram_Body_Stub --
1955 ----------------------------------
1957 -- A subprogram body stub can appear with or without a previous spec. If
1958 -- there is one, then the analysis of the body will find it and verify
1959 -- conformance. The formals appearing in the specification of the stub play
1960 -- no role, except for requiring an additional conformance check. If there
1961 -- is no previous subprogram declaration, the stub acts as a spec, and
1962 -- provides the defining entity for the subprogram.
1964 procedure Analyze_Subprogram_Body_Stub
(N
: Node_Id
) is
1966 Opts
: Config_Switches_Type
;
1969 Check_Stub_Level
(N
);
1971 -- Verify that the identifier for the stub is unique within this
1972 -- declarative part.
1974 if Nkind_In
(Parent
(N
), N_Block_Statement
,
1978 Decl
:= First
(Declarations
(Parent
(N
)));
1979 while Present
(Decl
) and then Decl
/= N
loop
1980 if Nkind
(Decl
) = N_Subprogram_Body_Stub
1981 and then (Chars
(Defining_Unit_Name
(Specification
(Decl
))) =
1982 Chars
(Defining_Unit_Name
(Specification
(N
))))
1984 Error_Msg_N
("identifier for stub is not unique", N
);
1991 -- Retain and restore the configuration options of the enclosing context
1992 -- as the proper body may introduce a set of its own.
1994 Save_Opt_Config_Switches
(Opts
);
1996 -- Treat stub as a body, which checks conformance if there is a previous
1997 -- declaration, or else introduces entity and its signature.
1999 Analyze_Subprogram_Body
(N
);
2000 Analyze_Proper_Body
(N
, Empty
);
2002 Restore_Opt_Config_Switches
(Opts
);
2003 end Analyze_Subprogram_Body_Stub
;
2005 ---------------------
2006 -- Analyze_Subunit --
2007 ---------------------
2009 -- A subunit is compiled either by itself (for semantic checking) or as
2010 -- part of compiling the parent (for code generation). In either case, by
2011 -- the time we actually process the subunit, the parent has already been
2012 -- installed and analyzed. The node N is a compilation unit, whose context
2013 -- needs to be treated here, because we come directly here from the parent
2014 -- without calling Analyze_Compilation_Unit.
2016 -- The compilation context includes the explicit context of the subunit,
2017 -- and the context of the parent, together with the parent itself. In order
2018 -- to compile the current context, we remove the one inherited from the
2019 -- parent, in order to have a clean visibility table. We restore the parent
2020 -- context before analyzing the proper body itself. On exit, we remove only
2021 -- the explicit context of the subunit.
2023 procedure Analyze_Subunit
(N
: Node_Id
) is
2024 Lib_Unit
: constant Node_Id
:= Library_Unit
(N
);
2025 Par_Unit
: constant Entity_Id
:= Current_Scope
;
2027 Lib_Spec
: Node_Id
:= Library_Unit
(Lib_Unit
);
2028 Num_Scopes
: Int
:= 0;
2029 Use_Clauses
: array (1 .. Scope_Stack
.Last
) of Node_Id
;
2030 Enclosing_Child
: Entity_Id
:= Empty
;
2031 Svg
: constant Suppress_Record
:= Scope_Suppress
;
2033 Save_Cunit_Restrictions
: constant Save_Cunit_Boolean_Restrictions
:=
2034 Cunit_Boolean_Restrictions_Save
;
2035 -- Save non-partition wide restrictions before processing the subunit.
2036 -- All subunits are analyzed with config restrictions reset and we need
2037 -- to restore these saved values at the end.
2039 procedure Analyze_Subunit_Context
;
2040 -- Capture names in use clauses of the subunit. This must be done before
2041 -- re-installing parent declarations, because items in the context must
2042 -- not be hidden by declarations local to the parent.
2044 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
);
2045 -- Recursive procedure to restore scope of all ancestors of subunit,
2046 -- from outermost in. If parent is not a subunit, the call to install
2047 -- context installs context of spec and (if parent is a child unit) the
2048 -- context of its parents as well. It is confusing that parents should
2049 -- be treated differently in both cases, but the semantics are just not
2052 procedure Re_Install_Use_Clauses
;
2053 -- As part of the removal of the parent scope, the use clauses are
2054 -- removed, to be reinstalled when the context of the subunit has been
2055 -- analyzed. Use clauses may also have been affected by the analysis of
2056 -- the context of the subunit, so they have to be applied again, to
2057 -- insure that the compilation environment of the rest of the parent
2058 -- unit is identical.
2060 procedure Remove_Scope
;
2061 -- Remove current scope from scope stack, and preserve the list of use
2062 -- clauses in it, to be reinstalled after context is analyzed.
2064 -----------------------------
2065 -- Analyze_Subunit_Context --
2066 -----------------------------
2068 procedure Analyze_Subunit_Context
is
2071 Unit_Name
: Entity_Id
;
2074 Analyze_Context
(N
);
2075 Check_No_Elab_Code_All
(N
);
2077 -- Make withed units immediately visible. If child unit, make the
2078 -- ultimate parent immediately visible.
2080 Item
:= First
(Context_Items
(N
));
2081 while Present
(Item
) loop
2082 if Nkind
(Item
) = N_With_Clause
then
2084 -- Protect frontend against previous errors in context clauses
2086 if Nkind
(Name
(Item
)) /= N_Selected_Component
then
2087 if Error_Posted
(Item
) then
2091 -- If a subunits has serious syntax errors, the context
2092 -- may not have been loaded. Add a harmless unit name to
2093 -- attempt processing.
2095 if Serious_Errors_Detected
> 0
2096 and then No
(Entity
(Name
(Item
)))
2098 Set_Entity
(Name
(Item
), Standard_Standard
);
2101 Unit_Name
:= Entity
(Name
(Item
));
2103 Set_Is_Visible_Lib_Unit
(Unit_Name
);
2104 exit when Scope
(Unit_Name
) = Standard_Standard
;
2105 Unit_Name
:= Scope
(Unit_Name
);
2107 if No
(Unit_Name
) then
2108 Check_Error_Detected
;
2113 if not Is_Immediately_Visible
(Unit_Name
) then
2114 Set_Is_Immediately_Visible
(Unit_Name
);
2115 Set_Context_Installed
(Item
);
2120 elsif Nkind
(Item
) = N_Use_Package_Clause
then
2121 Nam
:= First
(Names
(Item
));
2122 while Present
(Nam
) loop
2127 elsif Nkind
(Item
) = N_Use_Type_Clause
then
2128 Nam
:= First
(Subtype_Marks
(Item
));
2129 while Present
(Nam
) loop
2138 -- Reset visibility of withed units. They will be made visible again
2139 -- when we install the subunit context.
2141 Item
:= First
(Context_Items
(N
));
2142 while Present
(Item
) loop
2143 if Nkind
(Item
) = N_With_Clause
2145 -- Protect frontend against previous errors in context clauses
2147 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2148 and then not Error_Posted
(Item
)
2150 Unit_Name
:= Entity
(Name
(Item
));
2152 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
2153 exit when Scope
(Unit_Name
) = Standard_Standard
;
2154 Unit_Name
:= Scope
(Unit_Name
);
2157 if Context_Installed
(Item
) then
2158 Set_Is_Immediately_Visible
(Unit_Name
, False);
2159 Set_Context_Installed
(Item
, False);
2165 end Analyze_Subunit_Context
;
2167 ------------------------
2168 -- Re_Install_Parents --
2169 ------------------------
2171 procedure Re_Install_Parents
(L
: Node_Id
; Scop
: Entity_Id
) is
2175 if Nkind
(Unit
(L
)) = N_Subunit
then
2176 Re_Install_Parents
(Library_Unit
(L
), Scope
(Scop
));
2179 Install_Context
(L
);
2181 -- If the subunit occurs within a child unit, we must restore the
2182 -- immediate visibility of any siblings that may occur in context.
2184 if Present
(Enclosing_Child
) then
2185 Install_Siblings
(Enclosing_Child
, L
);
2190 if Scop
/= Par_Unit
then
2191 Set_Is_Immediately_Visible
(Scop
);
2194 -- Make entities in scope visible again. For child units, restore
2195 -- visibility only if they are actually in context.
2197 E
:= First_Entity
(Current_Scope
);
2198 while Present
(E
) loop
2199 if not Is_Child_Unit
(E
) or else Is_Visible_Lib_Unit
(E
) then
2200 Set_Is_Immediately_Visible
(E
);
2206 -- A subunit appears within a body, and for a nested subunits all the
2207 -- parents are bodies. Restore full visibility of their private
2210 if Is_Package_Or_Generic_Package
(Scop
) then
2211 Set_In_Package_Body
(Scop
);
2212 Install_Private_Declarations
(Scop
);
2214 end Re_Install_Parents
;
2216 ----------------------------
2217 -- Re_Install_Use_Clauses --
2218 ----------------------------
2220 procedure Re_Install_Use_Clauses
is
2223 for J
in reverse 1 .. Num_Scopes
loop
2224 U
:= Use_Clauses
(J
);
2225 Scope_Stack
.Table
(Scope_Stack
.Last
- J
+ 1).First_Use_Clause
:= U
;
2226 Install_Use_Clauses
(U
, Force_Installation
=> True);
2228 end Re_Install_Use_Clauses
;
2234 procedure Remove_Scope
is
2238 Num_Scopes
:= Num_Scopes
+ 1;
2239 Use_Clauses
(Num_Scopes
) :=
2240 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
;
2242 E
:= First_Entity
(Current_Scope
);
2243 while Present
(E
) loop
2244 Set_Is_Immediately_Visible
(E
, False);
2248 if Is_Child_Unit
(Current_Scope
) then
2249 Enclosing_Child
:= Current_Scope
;
2255 -- Start of processing for Analyze_Subunit
2258 -- For subunit in main extended unit, we reset the configuration values
2259 -- for the non-partition-wide restrictions. For other units reset them.
2261 if In_Extended_Main_Source_Unit
(N
) then
2262 Restore_Config_Cunit_Boolean_Restrictions
;
2264 Reset_Cunit_Boolean_Restrictions
;
2269 Nam
: Node_Id
:= Name
(Unit
(N
));
2272 if Nkind
(Nam
) = N_Selected_Component
then
2273 Nam
:= Selector_Name
(Nam
);
2276 Check_Identifier
(Nam
, Par_Unit
);
2280 if not Is_Empty_List
(Context_Items
(N
)) then
2282 -- Save current use clauses
2285 Remove_Context
(Lib_Unit
);
2287 -- Now remove parents and their context, including enclosing subunits
2288 -- and the outer parent body which is not a subunit.
2290 if Present
(Lib_Spec
) then
2291 Remove_Context
(Lib_Spec
);
2293 while Nkind
(Unit
(Lib_Spec
)) = N_Subunit
loop
2294 Lib_Spec
:= Library_Unit
(Lib_Spec
);
2296 Remove_Context
(Lib_Spec
);
2299 if Nkind
(Unit
(Lib_Unit
)) = N_Subunit
then
2303 if Nkind
(Unit
(Lib_Spec
)) = N_Package_Body
then
2304 Remove_Context
(Library_Unit
(Lib_Spec
));
2308 Set_Is_Immediately_Visible
(Par_Unit
, False);
2310 Analyze_Subunit_Context
;
2312 Re_Install_Parents
(Lib_Unit
, Par_Unit
);
2313 Set_Is_Immediately_Visible
(Par_Unit
);
2315 -- If the context includes a child unit of the parent of the subunit,
2316 -- the parent will have been removed from visibility, after compiling
2317 -- that cousin in the context. The visibility of the parent must be
2318 -- restored now. This also applies if the context includes another
2319 -- subunit of the same parent which in turn includes a child unit in
2322 if Is_Package_Or_Generic_Package
(Par_Unit
) then
2323 if not Is_Immediately_Visible
(Par_Unit
)
2324 or else (Present
(First_Entity
(Par_Unit
))
2326 Is_Immediately_Visible
(First_Entity
(Par_Unit
)))
2328 Set_Is_Immediately_Visible
(Par_Unit
);
2329 Install_Visible_Declarations
(Par_Unit
);
2330 Install_Private_Declarations
(Par_Unit
);
2334 Re_Install_Use_Clauses
;
2335 Install_Context
(N
);
2337 -- Restore state of suppress flags for current body
2339 Scope_Suppress
:= Svg
;
2341 -- If the subunit is within a child unit, then siblings of any parent
2342 -- unit that appear in the context clause of the subunit must also be
2343 -- made immediately visible.
2345 if Present
(Enclosing_Child
) then
2346 Install_Siblings
(Enclosing_Child
, N
);
2350 Generate_Parent_References
(Unit
(N
), Par_Unit
);
2351 Analyze
(Proper_Body
(Unit
(N
)));
2354 -- The subunit may contain a with_clause on a sibling of some ancestor.
2355 -- Removing the context will remove from visibility those ancestor child
2356 -- units, which must be restored to the visibility they have in the
2359 if Present
(Enclosing_Child
) then
2364 while Present
(C
) and then C
/= Standard_Standard
loop
2365 Set_Is_Immediately_Visible
(C
);
2366 Set_Is_Visible_Lib_Unit
(C
);
2372 -- Deal with restore of restrictions
2374 Cunit_Boolean_Restrictions_Restore
(Save_Cunit_Restrictions
);
2375 end Analyze_Subunit
;
2377 ----------------------------
2378 -- Analyze_Task_Body_Stub --
2379 ----------------------------
2381 procedure Analyze_Task_Body_Stub
(N
: Node_Id
) is
2382 Loc
: constant Source_Ptr
:= Sloc
(N
);
2383 Nam
: Entity_Id
:= Current_Entity_In_Scope
(Defining_Identifier
(N
));
2386 Check_Stub_Level
(N
);
2388 -- First occurrence of name may have been as an incomplete type
2390 if Present
(Nam
) and then Ekind
(Nam
) = E_Incomplete_Type
then
2391 Nam
:= Full_View
(Nam
);
2394 if No
(Nam
) or else not Is_Task_Type
(Etype
(Nam
)) then
2395 Error_Msg_N
("missing specification for task body", N
);
2398 -- Currently there are no language-defined aspects that can apply to
2399 -- a task body stub. Issue an error and remove the aspects to prevent
2402 if Has_Aspects
(N
) then
2404 ("aspects on task bodies are not allowed",
2405 First
(Aspect_Specifications
(N
)));
2409 Set_Scope
(Defining_Entity
(N
), Current_Scope
);
2410 Generate_Reference
(Nam
, Defining_Identifier
(N
), 'b');
2411 Set_Corresponding_Spec_Of_Stub
(N
, Nam
);
2413 -- Check for duplicate stub, if so give message and terminate
2415 if Has_Completion
(Etype
(Nam
)) then
2416 Error_Msg_N
("duplicate stub for task", N
);
2419 Set_Has_Completion
(Etype
(Nam
));
2422 Analyze_Proper_Body
(N
, Etype
(Nam
));
2424 -- Set elaboration flag to indicate that entity is callable. This
2425 -- cannot be done in the expansion of the body itself, because the
2426 -- proper body is not in a declarative part. This is only done if
2427 -- expansion is active, because the context may be generic and the
2428 -- flag not defined yet.
2430 if Expander_Active
then
2432 Make_Assignment_Statement
(Loc
,
2434 Make_Identifier
(Loc
,
2435 Chars
=> New_External_Name
(Chars
(Etype
(Nam
)), 'E')),
2436 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
2439 end Analyze_Task_Body_Stub
;
2441 -------------------------
2442 -- Analyze_With_Clause --
2443 -------------------------
2445 -- Analyze the declaration of a unit in a with clause. At end, label the
2446 -- with clause with the defining entity for the unit.
2448 procedure Analyze_With_Clause
(N
: Node_Id
) is
2450 -- Retrieve the original kind of the unit node, before analysis. If it
2451 -- is a subprogram instantiation, its analysis below will rewrite the
2452 -- node as the declaration of the wrapper package. If the same
2453 -- instantiation appears indirectly elsewhere in the context, it will
2454 -- have been analyzed already.
2456 Unit_Kind
: constant Node_Kind
:=
2457 Nkind
(Original_Node
(Unit
(Library_Unit
(N
))));
2458 Nam
: constant Node_Id
:= Name
(N
);
2460 Par_Name
: Entity_Id
;
2465 -- Set True if the unit currently being compiled is an internal unit
2467 Restriction_Violation
: Boolean := False;
2468 -- Set True if a with violates a restriction, no point in giving any
2469 -- warnings if we have this definite error.
2471 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
2474 U
:= Unit
(Library_Unit
(N
));
2476 -- If this is an internal unit which is a renaming, then this is a
2477 -- violation of No_Obsolescent_Features.
2479 -- Note: this is not quite right if the user defines one of these units
2480 -- himself, but that's a marginal case, and fixing it is hard ???
2482 if Restriction_Check_Required
(No_Obsolescent_Features
) then
2484 F
: constant File_Name_Type
:=
2485 Unit_File_Name
(Get_Source_Unit
(U
));
2487 if Is_Predefined_File_Name
(F
, Renamings_Included
=> True)
2489 Is_Predefined_File_Name
(F
, Renamings_Included
=> False)
2491 Check_Restriction
(No_Obsolescent_Features
, N
);
2492 Restriction_Violation
:= True;
2497 -- Check No_Implementation_Units violation
2499 if Restriction_Check_Required
(No_Implementation_Units
) then
2500 if Not_Impl_Defined_Unit
(Get_Source_Unit
(U
)) then
2503 Check_Restriction
(No_Implementation_Units
, Nam
);
2504 Restriction_Violation
:= True;
2508 -- Several actions are skipped for dummy packages (those supplied for
2509 -- with's where no matching file could be found). Such packages are
2510 -- identified by the Sloc value being set to No_Location.
2512 if Limited_Present
(N
) then
2514 -- Ada 2005 (AI-50217): Build visibility structures but do not
2515 -- analyze the unit.
2517 if Sloc
(U
) /= No_Location
then
2518 Build_Limited_Views
(N
);
2524 -- If the library unit is a predefined unit, and we are in high
2525 -- integrity mode, then temporarily reset Configurable_Run_Time_Mode
2526 -- for the analysis of the with'ed unit. This mode does not prevent
2527 -- explicit with'ing of run-time units.
2529 if Configurable_Run_Time_Mode
2530 and then Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(U
)))
2532 Configurable_Run_Time_Mode
:= False;
2533 Semantics
(Library_Unit
(N
));
2534 Configurable_Run_Time_Mode
:= True;
2537 Semantics
(Library_Unit
(N
));
2540 Intunit
:= Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
));
2542 if Sloc
(U
) /= No_Location
then
2544 -- Check restrictions, except that we skip the check if this is an
2545 -- internal unit unless we are compiling the internal unit as the
2546 -- main unit. We also skip this for dummy packages.
2548 Check_Restriction_No_Dependence
(Nam
, N
);
2550 if not Intunit
or else Current_Sem_Unit
= Main_Unit
then
2551 Check_Restricted_Unit
(Unit_Name
(Get_Source_Unit
(U
)), N
);
2554 -- Deal with special case of GNAT.Current_Exceptions which interacts
2555 -- with the optimization of local raise statements into gotos.
2557 if Nkind
(Nam
) = N_Selected_Component
2558 and then Nkind
(Prefix
(Nam
)) = N_Identifier
2559 and then Chars
(Prefix
(Nam
)) = Name_Gnat
2560 and then Nam_In
(Chars
(Selector_Name
(Nam
)),
2561 Name_Most_Recent_Exception
,
2562 Name_Exception_Traces
)
2564 Check_Restriction
(No_Exception_Propagation
, N
);
2565 Special_Exception_Package_Used
:= True;
2568 -- Check for inappropriate with of internal implementation unit if we
2569 -- are not compiling an internal unit and also check for withing unit
2570 -- in wrong version of Ada. Do not issue these messages for implicit
2571 -- with's generated by the compiler itself.
2573 if Implementation_Unit_Warnings
2574 and then not Intunit
2575 and then not Implicit_With
(N
)
2576 and then not Restriction_Violation
2579 U_Kind
: constant Kind_Of_Unit
:=
2580 Get_Kind_Of_Unit
(Get_Source_Unit
(U
));
2583 if U_Kind
= Implementation_Unit
then
2584 Error_Msg_F
("& is an internal 'G'N'A'T unit?i?", Name
(N
));
2586 -- Add alternative name if available, otherwise issue a
2587 -- general warning message.
2589 if Error_Msg_Strlen
/= 0 then
2590 Error_Msg_F
("\use ""~"" instead?i?", Name
(N
));
2593 ("\use of this unit is non-portable " &
2594 "and version-dependent?i?", Name
(N
));
2597 elsif U_Kind
= Ada_2005_Unit
2598 and then Ada_Version
< Ada_2005
2599 and then Warn_On_Ada_2005_Compatibility
2601 Error_Msg_N
("& is an Ada 2005 unit?i?", Name
(N
));
2603 elsif U_Kind
= Ada_2012_Unit
2604 and then Ada_Version
< Ada_2012
2605 and then Warn_On_Ada_2012_Compatibility
2607 Error_Msg_N
("& is an Ada 2012 unit?i?", Name
(N
));
2613 -- Semantic analysis of a generic unit is performed on a copy of
2614 -- the original tree. Retrieve the entity on which semantic info
2615 -- actually appears.
2617 if Unit_Kind
in N_Generic_Declaration
then
2618 E_Name
:= Defining_Entity
(U
);
2620 -- Note: in the following test, Unit_Kind is the original Nkind, but in
2621 -- the case of an instantiation, semantic analysis above will have
2622 -- replaced the unit by its instantiated version. If the instance body
2623 -- has been generated, the instance now denotes the body entity. For
2624 -- visibility purposes we need the entity of its spec.
2626 elsif (Unit_Kind
= N_Package_Instantiation
2627 or else Nkind
(Original_Node
(Unit
(Library_Unit
(N
)))) =
2628 N_Package_Instantiation
)
2629 and then Nkind
(U
) = N_Package_Body
2631 E_Name
:= Corresponding_Spec
(U
);
2633 elsif Unit_Kind
= N_Package_Instantiation
2634 and then Nkind
(U
) = N_Package_Instantiation
2635 and then Present
(Instance_Spec
(U
))
2637 -- If the instance has not been rewritten as a package declaration,
2638 -- then it appeared already in a previous with clause. Retrieve
2639 -- the entity from the previous instance.
2641 E_Name
:= Defining_Entity
(Specification
(Instance_Spec
(U
)));
2643 elsif Unit_Kind
in N_Subprogram_Instantiation
then
2645 -- The visible subprogram is created during instantiation, and is
2646 -- an attribute of the wrapper package. We retrieve the wrapper
2647 -- package directly from the instantiation node. If the instance
2648 -- is inlined the unit is still an instantiation. Otherwise it has
2649 -- been rewritten as the declaration of the wrapper itself.
2651 if Nkind
(U
) in N_Subprogram_Instantiation
then
2654 (Defining_Entity
(Specification
(Instance_Spec
(U
))));
2656 E_Name
:= Related_Instance
(Defining_Entity
(U
));
2659 elsif Unit_Kind
= N_Package_Renaming_Declaration
2660 or else Unit_Kind
in N_Generic_Renaming_Declaration
2662 E_Name
:= Defining_Entity
(U
);
2664 elsif Unit_Kind
= N_Subprogram_Body
2665 and then Nkind
(Name
(N
)) = N_Selected_Component
2666 and then not Acts_As_Spec
(Library_Unit
(N
))
2668 -- For a child unit that has no spec, one has been created and
2669 -- analyzed. The entity required is that of the spec.
2671 E_Name
:= Corresponding_Spec
(U
);
2674 E_Name
:= Defining_Entity
(U
);
2677 if Nkind
(Name
(N
)) = N_Selected_Component
then
2679 -- Child unit in a with clause
2681 Change_Selected_Component_To_Expanded_Name
(Name
(N
));
2683 -- If this is a child unit without a spec, and it has been analyzed
2684 -- already, a declaration has been created for it. The with_clause
2685 -- must reflect the actual body, and not the generated declaration,
2686 -- to prevent spurious binding errors involving an out-of-date spec.
2687 -- Note that this can only happen if the unit includes more than one
2688 -- with_clause for the child unit (e.g. in separate subunits).
2690 if Unit_Kind
= N_Subprogram_Declaration
2691 and then Analyzed
(Library_Unit
(N
))
2692 and then not Comes_From_Source
(Library_Unit
(N
))
2694 Set_Library_Unit
(N
,
2695 Cunit
(Get_Source_Unit
(Corresponding_Body
(U
))));
2699 -- Restore style checks
2701 Style_Check
:= Save_Style_Check
;
2703 -- Record the reference, but do NOT set the unit as referenced, we want
2704 -- to consider the unit as unreferenced if this is the only reference
2707 Set_Entity_With_Checks
(Name
(N
), E_Name
);
2708 Generate_Reference
(E_Name
, Name
(N
), 'w', Set_Ref
=> False);
2710 -- Generate references and check No_Dependence restriction for parents
2712 if Is_Child_Unit
(E_Name
) then
2713 Pref
:= Prefix
(Name
(N
));
2714 Par_Name
:= Scope
(E_Name
);
2715 while Nkind
(Pref
) = N_Selected_Component
loop
2716 Change_Selected_Component_To_Expanded_Name
(Pref
);
2718 if Present
(Entity
(Selector_Name
(Pref
)))
2720 Present
(Renamed_Entity
(Entity
(Selector_Name
(Pref
))))
2721 and then Entity
(Selector_Name
(Pref
)) /= Par_Name
2723 -- The prefix is a child unit that denotes a renaming declaration.
2724 -- Replace the prefix directly with the renamed unit, because the
2725 -- rest of the prefix is irrelevant to the visibility of the real
2728 Rewrite
(Pref
, New_Occurrence_Of
(Par_Name
, Sloc
(Pref
)));
2732 Set_Entity_With_Checks
(Pref
, Par_Name
);
2734 Generate_Reference
(Par_Name
, Pref
);
2735 Check_Restriction_No_Dependence
(Pref
, N
);
2736 Pref
:= Prefix
(Pref
);
2738 -- If E_Name is the dummy entity for a nonexistent unit, its scope
2739 -- is set to Standard_Standard, and no attempt should be made to
2740 -- further unwind scopes.
2742 if Par_Name
/= Standard_Standard
then
2743 Par_Name
:= Scope
(Par_Name
);
2746 -- Abandon processing in case of previous errors
2748 if No
(Par_Name
) then
2749 Check_Error_Detected
;
2754 if Present
(Entity
(Pref
))
2755 and then not Analyzed
(Parent
(Parent
(Entity
(Pref
))))
2757 -- If the entity is set without its unit being compiled, the
2758 -- original parent is a renaming, and Par_Name is the renamed
2759 -- entity. For visibility purposes, we need the original entity,
2760 -- which must be analyzed now because Load_Unit directly retrieves
2761 -- the renamed unit, and the renaming declaration itself has not
2764 Analyze
(Parent
(Parent
(Entity
(Pref
))));
2765 pragma Assert
(Renamed_Object
(Entity
(Pref
)) = Par_Name
);
2766 Par_Name
:= Entity
(Pref
);
2769 -- Guard against missing or misspelled child units
2771 if Present
(Par_Name
) then
2772 Set_Entity_With_Checks
(Pref
, Par_Name
);
2773 Generate_Reference
(Par_Name
, Pref
);
2776 pragma Assert
(Serious_Errors_Detected
/= 0);
2778 -- Mark the node to indicate that a related error has been posted.
2779 -- This defends further compilation passes against improper use of
2780 -- the invalid WITH clause node.
2782 Set_Error_Posted
(N
);
2783 Set_Name
(N
, Error
);
2788 -- If the withed unit is System, and a system extension pragma is
2789 -- present, compile the extension now, rather than waiting for a
2790 -- visibility check on a specific entity.
2792 if Chars
(E_Name
) = Name_System
2793 and then Scope
(E_Name
) = Standard_Standard
2794 and then Present
(System_Extend_Unit
)
2795 and then Present_System_Aux
(N
)
2797 -- If the extension is not present, an error will have been emitted
2802 -- Ada 2005 (AI-262): Remove from visibility the entity corresponding
2803 -- to private_with units; they will be made visible later (just before
2804 -- the private part is analyzed)
2806 if Private_Present
(N
) then
2807 Set_Is_Immediately_Visible
(E_Name
, False);
2809 end Analyze_With_Clause
;
2811 ------------------------------
2812 -- Check_Private_Child_Unit --
2813 ------------------------------
2815 procedure Check_Private_Child_Unit
(N
: Node_Id
) is
2816 Lib_Unit
: constant Node_Id
:= Unit
(N
);
2818 Curr_Unit
: Entity_Id
;
2819 Sub_Parent
: Node_Id
;
2820 Priv_Child
: Entity_Id
;
2821 Par_Lib
: Entity_Id
;
2824 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean;
2825 -- Returns true if and only if the library unit is declared with
2826 -- an explicit designation of private.
2828 -----------------------------
2829 -- Is_Private_Library_Unit --
2830 -----------------------------
2832 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean is
2833 Comp_Unit
: constant Node_Id
:= Parent
(Unit_Declaration_Node
(Unit
));
2836 return Private_Present
(Comp_Unit
);
2837 end Is_Private_Library_Unit
;
2839 -- Start of processing for Check_Private_Child_Unit
2842 if Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subprogram_Body
) then
2843 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(N
)));
2844 Par_Lib
:= Curr_Unit
;
2846 elsif Nkind
(Lib_Unit
) = N_Subunit
then
2848 -- The parent is itself a body. The parent entity is to be found in
2849 -- the corresponding spec.
2851 Sub_Parent
:= Library_Unit
(N
);
2852 Curr_Unit
:= Defining_Entity
(Unit
(Library_Unit
(Sub_Parent
)));
2854 -- If the parent itself is a subunit, Curr_Unit is the entity of the
2855 -- enclosing body, retrieve the spec entity which is the proper
2856 -- ancestor we need for the following tests.
2858 if Ekind
(Curr_Unit
) = E_Package_Body
then
2859 Curr_Unit
:= Spec_Entity
(Curr_Unit
);
2862 Par_Lib
:= Curr_Unit
;
2865 Curr_Unit
:= Defining_Entity
(Lib_Unit
);
2867 Par_Lib
:= Curr_Unit
;
2868 Par_Spec
:= Parent_Spec
(Lib_Unit
);
2870 if No
(Par_Spec
) then
2873 Par_Lib
:= Defining_Entity
(Unit
(Par_Spec
));
2877 -- Loop through context items
2879 Item
:= First
(Context_Items
(N
));
2880 while Present
(Item
) loop
2882 -- Ada 2005 (AI-262): Allow private_with of a private child package
2883 -- in public siblings
2885 if Nkind
(Item
) = N_With_Clause
2886 and then not Implicit_With
(Item
)
2887 and then not Limited_Present
(Item
)
2888 and then Is_Private_Descendant
(Entity
(Name
(Item
)))
2890 Priv_Child
:= Entity
(Name
(Item
));
2893 Curr_Parent
: Entity_Id
:= Par_Lib
;
2894 Child_Parent
: Entity_Id
:= Scope
(Priv_Child
);
2895 Prv_Ancestor
: Entity_Id
:= Child_Parent
;
2896 Curr_Private
: Boolean := Is_Private_Library_Unit
(Curr_Unit
);
2899 -- If the child unit is a public child then locate the nearest
2900 -- private ancestor. Child_Parent will then be set to the
2901 -- parent of that ancestor.
2903 if not Is_Private_Library_Unit
(Priv_Child
) then
2904 while Present
(Prv_Ancestor
)
2905 and then not Is_Private_Library_Unit
(Prv_Ancestor
)
2907 Prv_Ancestor
:= Scope
(Prv_Ancestor
);
2910 if Present
(Prv_Ancestor
) then
2911 Child_Parent
:= Scope
(Prv_Ancestor
);
2915 while Present
(Curr_Parent
)
2916 and then Curr_Parent
/= Standard_Standard
2917 and then Curr_Parent
/= Child_Parent
2920 Curr_Private
or else Is_Private_Library_Unit
(Curr_Parent
);
2921 Curr_Parent
:= Scope
(Curr_Parent
);
2924 if No
(Curr_Parent
) then
2925 Curr_Parent
:= Standard_Standard
;
2928 if Curr_Parent
/= Child_Parent
then
2929 if Ekind
(Priv_Child
) = E_Generic_Package
2930 and then Chars
(Priv_Child
) in Text_IO_Package_Name
2931 and then Chars
(Scope
(Scope
(Priv_Child
))) = Name_Ada
2934 ("& is a nested package, not a compilation unit",
2935 Name
(Item
), Priv_Child
);
2939 ("unit in with clause is private child unit!", Item
);
2941 ("\current unit must also have parent&!",
2942 Item
, Child_Parent
);
2946 or else Private_Present
(Item
)
2947 or else Nkind_In
(Lib_Unit
, N_Package_Body
, N_Subunit
)
2948 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
2949 and then not Acts_As_Spec
(Parent
(Lib_Unit
)))
2955 ("current unit must also be private descendant of&",
2956 Item
, Child_Parent
);
2964 end Check_Private_Child_Unit
;
2966 ----------------------
2967 -- Check_Stub_Level --
2968 ----------------------
2970 procedure Check_Stub_Level
(N
: Node_Id
) is
2971 Par
: constant Node_Id
:= Parent
(N
);
2972 Kind
: constant Node_Kind
:= Nkind
(Par
);
2975 if Nkind_In
(Kind
, N_Package_Body
,
2979 and then Nkind_In
(Parent
(Par
), N_Compilation_Unit
, N_Subunit
)
2983 -- In an instance, a missing stub appears at any level. A warning
2984 -- message will have been emitted already for the missing file.
2986 elsif not In_Instance
then
2987 Error_Msg_N
("stub cannot appear in an inner scope", N
);
2989 elsif Expander_Active
then
2990 Error_Msg_N
("missing proper body", N
);
2992 end Check_Stub_Level
;
2994 ------------------------
2995 -- Expand_With_Clause --
2996 ------------------------
2998 procedure Expand_With_Clause
(Item
: Node_Id
; Nam
: Node_Id
; N
: Node_Id
) is
2999 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3000 Ent
: constant Entity_Id
:= Entity
(Nam
);
3004 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
;
3005 -- Build name to be used in implicit with_clause. In most cases this
3006 -- is the source name, but if renamings are present we must make the
3007 -- original unit visible, not the one it renames. The entity in the
3008 -- with clause is the renamed unit, but the identifier is the one from
3009 -- the source, which allows us to recover the unit renaming.
3011 ---------------------
3012 -- Build_Unit_Name --
3013 ---------------------
3015 function Build_Unit_Name
(Nam
: Node_Id
) return Node_Id
is
3020 if Nkind
(Nam
) = N_Identifier
then
3021 return New_Occurrence_Of
(Entity
(Nam
), Loc
);
3024 Ent
:= Entity
(Nam
);
3026 if Present
(Entity
(Selector_Name
(Nam
)))
3027 and then Chars
(Entity
(Selector_Name
(Nam
))) /= Chars
(Ent
)
3029 Nkind
(Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
))))
3030 = N_Package_Renaming_Declaration
3032 -- The name in the with_clause is of the form A.B.C, and B is
3033 -- given by a renaming declaration. In that case we may not
3034 -- have analyzed the unit for B, but replaced it directly in
3035 -- lib-load with the unit it renames. We have to make A.B
3036 -- visible, so analyze the declaration for B now, in case it
3037 -- has not been done yet.
3039 Ent
:= Entity
(Selector_Name
(Nam
));
3042 (Unit_Declaration_Node
(Entity
(Selector_Name
(Nam
)))));
3046 Make_Expanded_Name
(Loc
,
3047 Chars
=> Chars
(Entity
(Nam
)),
3048 Prefix
=> Build_Unit_Name
(Prefix
(Nam
)),
3049 Selector_Name
=> New_Occurrence_Of
(Ent
, Loc
));
3050 Set_Entity
(Result
, Ent
);
3053 end Build_Unit_Name
;
3055 -- Start of processing for Expand_With_Clause
3059 Make_With_Clause
(Loc
,
3060 Name
=> Build_Unit_Name
(Nam
));
3062 P
:= Parent
(Unit_Declaration_Node
(Ent
));
3063 Set_Library_Unit
(Withn
, P
);
3064 Set_Corresponding_Spec
(Withn
, Ent
);
3065 Set_First_Name
(Withn
, True);
3066 Set_Implicit_With
(Withn
, True);
3068 -- If the unit is a package or generic package declaration, a private_
3069 -- with_clause on a child unit implies that the implicit with on the
3070 -- parent is also private.
3072 if Nkind_In
(Unit
(N
), N_Package_Declaration
,
3073 N_Generic_Package_Declaration
)
3075 Set_Private_Present
(Withn
, Private_Present
(Item
));
3078 Prepend
(Withn
, Context_Items
(N
));
3079 Mark_Rewrite_Insertion
(Withn
);
3080 Install_Withed_Unit
(Withn
);
3082 -- If we have "with X.Y;", we want to recurse on "X", except in the
3083 -- unusual case where X.Y is a renaming of X. In that case, the scope
3084 -- of X will be null.
3086 if Nkind
(Nam
) = N_Expanded_Name
3087 and then Present
(Scope
(Entity
(Prefix
(Nam
))))
3089 Expand_With_Clause
(Item
, Prefix
(Nam
), N
);
3091 end Expand_With_Clause
;
3093 --------------------------------
3094 -- Generate_Parent_References --
3095 --------------------------------
3097 procedure Generate_Parent_References
(N
: Node_Id
; P_Id
: Entity_Id
) is
3099 P_Name
: Entity_Id
:= P_Id
;
3102 if Nkind
(N
) = N_Subunit
then
3105 Pref
:= Name
(Parent
(Defining_Entity
(N
)));
3108 if Nkind
(Pref
) = N_Expanded_Name
then
3110 -- Done already, if the unit has been compiled indirectly as
3111 -- part of the closure of its context because of inlining.
3116 while Nkind
(Pref
) = N_Selected_Component
loop
3117 Change_Selected_Component_To_Expanded_Name
(Pref
);
3118 Set_Entity
(Pref
, P_Name
);
3119 Set_Etype
(Pref
, Etype
(P_Name
));
3120 Generate_Reference
(P_Name
, Pref
, 'r');
3121 Pref
:= Prefix
(Pref
);
3122 P_Name
:= Scope
(P_Name
);
3125 -- The guard here on P_Name is to handle the error condition where
3126 -- the parent unit is missing because the file was not found.
3128 if Present
(P_Name
) then
3129 Set_Entity
(Pref
, P_Name
);
3130 Set_Etype
(Pref
, Etype
(P_Name
));
3131 Generate_Reference
(P_Name
, Pref
, 'r');
3132 Style
.Check_Identifier
(Pref
, P_Name
);
3134 end Generate_Parent_References
;
3136 ---------------------
3137 -- Has_With_Clause --
3138 ---------------------
3140 function Has_With_Clause
3143 Is_Limited
: Boolean := False) return Boolean
3147 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
;
3148 -- Return the entity for the unit named in a [limited] with clause
3154 function Named_Unit
(Clause
: Node_Id
) return Entity_Id
is
3156 if Nkind
(Name
(Clause
)) = N_Selected_Component
then
3157 return Entity
(Selector_Name
(Name
(Clause
)));
3159 return Entity
(Name
(Clause
));
3163 -- Start of processing for Has_With_Clause
3166 if Present
(Context_Items
(C_Unit
)) then
3167 Item
:= First
(Context_Items
(C_Unit
));
3168 while Present
(Item
) loop
3169 if Nkind
(Item
) = N_With_Clause
3170 and then Limited_Present
(Item
) = Is_Limited
3171 and then Named_Unit
(Item
) = Pack
3181 end Has_With_Clause
;
3183 -----------------------------
3184 -- Implicit_With_On_Parent --
3185 -----------------------------
3187 procedure Implicit_With_On_Parent
3188 (Child_Unit
: Node_Id
;
3191 Loc
: constant Source_Ptr
:= Sloc
(N
);
3192 P
: constant Node_Id
:= Parent_Spec
(Child_Unit
);
3193 P_Unit
: Node_Id
:= Unit
(P
);
3194 P_Name
: constant Entity_Id
:= Get_Parent_Entity
(P_Unit
);
3197 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
;
3198 -- Build prefix of child unit name. Recurse if needed
3200 function Build_Unit_Name
return Node_Id
;
3201 -- If the unit is a child unit, build qualified name with all ancestors
3203 -------------------------
3204 -- Build_Ancestor_Name --
3205 -------------------------
3207 function Build_Ancestor_Name
(P
: Node_Id
) return Node_Id
is
3208 P_Ref
: constant Node_Id
:=
3209 New_Occurrence_Of
(Defining_Entity
(P
), Loc
);
3210 P_Spec
: Node_Id
:= P
;
3213 -- Ancestor may have been rewritten as a package body. Retrieve
3214 -- the original spec to trace earlier ancestors.
3216 if Nkind
(P
) = N_Package_Body
3217 and then Nkind
(Original_Node
(P
)) = N_Package_Instantiation
3219 P_Spec
:= Original_Node
(P
);
3222 if No
(Parent_Spec
(P_Spec
)) then
3226 Make_Selected_Component
(Loc
,
3227 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Spec
))),
3228 Selector_Name
=> P_Ref
);
3230 end Build_Ancestor_Name
;
3232 ---------------------
3233 -- Build_Unit_Name --
3234 ---------------------
3236 function Build_Unit_Name
return Node_Id
is
3240 if No
(Parent_Spec
(P_Unit
)) then
3241 return New_Occurrence_Of
(P_Name
, Loc
);
3245 Make_Expanded_Name
(Loc
,
3246 Chars
=> Chars
(P_Name
),
3247 Prefix
=> Build_Ancestor_Name
(Unit
(Parent_Spec
(P_Unit
))),
3248 Selector_Name
=> New_Occurrence_Of
(P_Name
, Loc
));
3249 Set_Entity
(Result
, P_Name
);
3252 end Build_Unit_Name
;
3254 -- Start of processing for Implicit_With_On_Parent
3257 -- The unit of the current compilation may be a package body that
3258 -- replaces an instance node. In this case we need the original instance
3259 -- node to construct the proper parent name.
3261 if Nkind
(P_Unit
) = N_Package_Body
3262 and then Nkind
(Original_Node
(P_Unit
)) = N_Package_Instantiation
3264 P_Unit
:= Original_Node
(P_Unit
);
3267 -- We add the implicit with if the child unit is the current unit being
3268 -- compiled. If the current unit is a body, we do not want to add an
3269 -- implicit_with a second time to the corresponding spec.
3271 if Nkind
(Child_Unit
) = N_Package_Declaration
3272 and then Child_Unit
/= Unit
(Cunit
(Current_Sem_Unit
))
3277 Withn
:= Make_With_Clause
(Loc
, Name
=> Build_Unit_Name
);
3279 Set_Library_Unit
(Withn
, P
);
3280 Set_Corresponding_Spec
(Withn
, P_Name
);
3281 Set_First_Name
(Withn
, True);
3282 Set_Implicit_With
(Withn
, True);
3284 -- Node is placed at the beginning of the context items, so that
3285 -- subsequent use clauses on the parent can be validated.
3287 Prepend
(Withn
, Context_Items
(N
));
3288 Mark_Rewrite_Insertion
(Withn
);
3289 Install_Withed_Unit
(Withn
);
3291 if Is_Child_Spec
(P_Unit
) then
3292 Implicit_With_On_Parent
(P_Unit
, N
);
3294 end Implicit_With_On_Parent
;
3300 function In_Chain
(E
: Entity_Id
) return Boolean is
3304 H
:= Current_Entity
(E
);
3305 while Present
(H
) loop
3316 ---------------------
3317 -- Install_Context --
3318 ---------------------
3320 procedure Install_Context
(N
: Node_Id
) is
3321 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3324 Install_Context_Clauses
(N
);
3326 if Is_Child_Spec
(Lib_Unit
) then
3327 Install_Parents
(Lib_Unit
, Private_Present
(Parent
(Lib_Unit
)));
3330 Install_Limited_Context_Clauses
(N
);
3331 end Install_Context
;
3333 -----------------------------
3334 -- Install_Context_Clauses --
3335 -----------------------------
3337 procedure Install_Context_Clauses
(N
: Node_Id
) is
3338 Lib_Unit
: constant Node_Id
:= Unit
(N
);
3340 Uname_Node
: Entity_Id
;
3341 Check_Private
: Boolean := False;
3342 Decl_Node
: Node_Id
;
3343 Lib_Parent
: Entity_Id
;
3346 -- First skip configuration pragmas at the start of the context. They
3347 -- are not technically part of the context clause, but that's where the
3348 -- parser puts them. Note they were analyzed in Analyze_Context.
3350 Item
:= First
(Context_Items
(N
));
3351 while Present
(Item
)
3352 and then Nkind
(Item
) = N_Pragma
3353 and then Pragma_Name
(Item
) in Configuration_Pragma_Names
3358 -- Loop through the actual context clause items. We process everything
3359 -- except Limited_With clauses in this routine. Limited_With clauses
3360 -- are separately installed (see Install_Limited_Context_Clauses).
3362 while Present
(Item
) loop
3364 -- Case of explicit WITH clause
3366 if Nkind
(Item
) = N_With_Clause
3367 and then not Implicit_With
(Item
)
3369 if Limited_Present
(Item
) then
3371 -- Limited withed units will be installed later
3375 -- If Name (Item) is not an entity name, something is wrong, and
3376 -- this will be detected in due course, for now ignore the item
3378 elsif not Is_Entity_Name
(Name
(Item
)) then
3381 elsif No
(Entity
(Name
(Item
))) then
3382 Set_Entity
(Name
(Item
), Any_Id
);
3386 Uname_Node
:= Entity
(Name
(Item
));
3388 if Is_Private_Descendant
(Uname_Node
) then
3389 Check_Private
:= True;
3392 Install_Withed_Unit
(Item
);
3394 Decl_Node
:= Unit_Declaration_Node
(Uname_Node
);
3396 -- If the unit is a subprogram instance, it appears nested within
3397 -- a package that carries the parent information.
3399 if Is_Generic_Instance
(Uname_Node
)
3400 and then Ekind
(Uname_Node
) /= E_Package
3402 Decl_Node
:= Parent
(Parent
(Decl_Node
));
3405 if Is_Child_Spec
(Decl_Node
) then
3406 if Nkind
(Name
(Item
)) = N_Expanded_Name
then
3407 Expand_With_Clause
(Item
, Prefix
(Name
(Item
)), N
);
3409 -- If not an expanded name, the child unit must be a
3410 -- renaming, nothing to do.
3415 elsif Nkind
(Decl_Node
) = N_Subprogram_Body
3416 and then not Acts_As_Spec
(Parent
(Decl_Node
))
3417 and then Is_Child_Spec
(Unit
(Library_Unit
(Parent
(Decl_Node
))))
3419 Implicit_With_On_Parent
3420 (Unit
(Library_Unit
(Parent
(Decl_Node
))), N
);
3423 -- Check license conditions unless this is a dummy unit
3425 if Sloc
(Library_Unit
(Item
)) /= No_Location
then
3426 License_Check
: declare
3427 Withu
: constant Unit_Number_Type
:=
3428 Get_Source_Unit
(Library_Unit
(Item
));
3429 Withl
: constant License_Type
:=
3430 License
(Source_Index
(Withu
));
3431 Unitl
: constant License_Type
:=
3432 License
(Source_Index
(Current_Sem_Unit
));
3434 procedure License_Error
;
3435 -- Signal error of bad license
3441 procedure License_Error
is
3444 ("license of withed unit & may be inconsistent??",
3448 -- Start of processing for License_Check
3451 -- Exclude license check if withed unit is an internal unit.
3452 -- This situation arises e.g. with the GPL version of GNAT.
3454 if Is_Internal_File_Name
(Unit_File_Name
(Withu
)) then
3457 -- Otherwise check various cases
3469 if Withl
= Restricted
then
3473 when Modified_GPL
=>
3474 if Withl
= Restricted
or else Withl
= GPL
then
3478 when Unrestricted
=>
3485 -- Case of USE PACKAGE clause
3487 elsif Nkind
(Item
) = N_Use_Package_Clause
then
3488 Analyze_Use_Package
(Item
);
3490 -- Case of USE TYPE clause
3492 elsif Nkind
(Item
) = N_Use_Type_Clause
then
3493 Analyze_Use_Type
(Item
);
3497 elsif Nkind
(Item
) = N_Pragma
then
3505 if Is_Child_Spec
(Lib_Unit
) then
3507 -- The unit also has implicit with_clauses on its own parents
3509 if No
(Context_Items
(N
)) then
3510 Set_Context_Items
(N
, New_List
);
3513 Implicit_With_On_Parent
(Lib_Unit
, N
);
3516 -- If the unit is a body, the context of the specification must also
3517 -- be installed. That includes private with_clauses in that context.
3519 if Nkind
(Lib_Unit
) = N_Package_Body
3520 or else (Nkind
(Lib_Unit
) = N_Subprogram_Body
3521 and then not Acts_As_Spec
(N
))
3523 Install_Context
(Library_Unit
(N
));
3525 -- Only install private with-clauses of a spec that comes from
3526 -- source, excluding specs created for a subprogram body that is
3529 if Comes_From_Source
(Library_Unit
(N
)) then
3530 Install_Private_With_Clauses
3531 (Defining_Entity
(Unit
(Library_Unit
(N
))));
3534 if Is_Child_Spec
(Unit
(Library_Unit
(N
))) then
3536 -- If the unit is the body of a public child unit, the private
3537 -- declarations of the parent must be made visible. If the child
3538 -- unit is private, the private declarations have been installed
3539 -- already in the call to Install_Parents for the spec. Installing
3540 -- private declarations must be done for all ancestors of public
3541 -- child units. In addition, sibling units mentioned in the
3542 -- context clause of the body are directly visible.
3550 Lib_Spec
:= Unit
(Library_Unit
(N
));
3551 while Is_Child_Spec
(Lib_Spec
) loop
3552 P
:= Unit
(Parent_Spec
(Lib_Spec
));
3553 P_Name
:= Defining_Entity
(P
);
3555 if not (Private_Present
(Parent
(Lib_Spec
)))
3556 and then not In_Private_Part
(P_Name
)
3558 Install_Private_Declarations
(P_Name
);
3559 Install_Private_With_Clauses
(P_Name
);
3560 Set_Use
(Private_Declarations
(Specification
(P
)));
3568 -- For a package body, children in context are immediately visible
3570 Install_Siblings
(Defining_Entity
(Unit
(Library_Unit
(N
))), N
);
3573 if Nkind_In
(Lib_Unit
, N_Generic_Package_Declaration
,
3574 N_Generic_Subprogram_Declaration
,
3575 N_Package_Declaration
,
3576 N_Subprogram_Declaration
)
3578 if Is_Child_Spec
(Lib_Unit
) then
3579 Lib_Parent
:= Defining_Entity
(Unit
(Parent_Spec
(Lib_Unit
)));
3580 Set_Is_Private_Descendant
3581 (Defining_Entity
(Lib_Unit
),
3582 Is_Private_Descendant
(Lib_Parent
)
3583 or else Private_Present
(Parent
(Lib_Unit
)));
3586 Set_Is_Private_Descendant
3587 (Defining_Entity
(Lib_Unit
),
3588 Private_Present
(Parent
(Lib_Unit
)));
3592 if Check_Private
then
3593 Check_Private_Child_Unit
(N
);
3595 end Install_Context_Clauses
;
3597 -------------------------------------
3598 -- Install_Limited_Context_Clauses --
3599 -------------------------------------
3601 procedure Install_Limited_Context_Clauses
(N
: Node_Id
) is
3604 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
);
3605 -- Check that the unlimited view of a given compilation_unit is not
3606 -- already visible through "use + renamings".
3608 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
);
3609 -- Check that if a limited_with clause of a given compilation_unit
3610 -- mentions a descendant of a private child of some library unit, then
3611 -- the given compilation_unit must be the declaration of a private
3612 -- descendant of that library unit, or a public descendant of such. The
3613 -- code is analogous to that of Check_Private_Child_Unit but we cannot
3614 -- use entities on the limited with_clauses because their units have not
3615 -- been analyzed, so we have to climb the tree of ancestors looking for
3616 -- private keywords.
3618 procedure Expand_Limited_With_Clause
3619 (Comp_Unit
: Node_Id
;
3622 -- If a child unit appears in a limited_with clause, there are implicit
3623 -- limited_with clauses on all parents that are not already visible
3624 -- through a regular with clause. This procedure creates the implicit
3625 -- limited with_clauses for the parents and loads the corresponding
3626 -- units. The shadow entities are created when the inserted clause is
3627 -- analyzed. Implements Ada 2005 (AI-50217).
3629 ---------------------
3630 -- Check_Renamings --
3631 ---------------------
3633 procedure Check_Renamings
(P
: Node_Id
; W
: Node_Id
) is
3642 pragma Assert
(Nkind
(W
) = N_With_Clause
);
3644 -- Protect the frontend against previous critical errors
3646 case Nkind
(Unit
(Library_Unit
(W
))) is
3647 when N_Subprogram_Declaration |
3648 N_Package_Declaration |
3649 N_Generic_Subprogram_Declaration |
3650 N_Generic_Package_Declaration
=>
3657 -- Check "use + renamings"
3659 WEnt
:= Defining_Unit_Name
(Specification
(Unit
(Library_Unit
(W
))));
3660 Spec
:= Specification
(Unit
(P
));
3662 Item
:= First
(Visible_Declarations
(Spec
));
3663 while Present
(Item
) loop
3665 -- Look only at use package clauses
3667 if Nkind
(Item
) = N_Use_Package_Clause
then
3669 -- Traverse the list of packages
3671 Nam
:= First
(Names
(Item
));
3672 while Present
(Nam
) loop
3675 pragma Assert
(Present
(Parent
(E
)));
3677 if Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
3678 and then Renamed_Entity
(E
) = WEnt
3680 -- The unlimited view is visible through use clause and
3681 -- renamings. There is no need to generate the error
3682 -- message here because Is_Visible_Through_Renamings
3683 -- takes care of generating the precise error message.
3687 elsif Nkind
(Parent
(E
)) = N_Package_Specification
then
3689 -- The use clause may refer to a local package.
3690 -- Check all the enclosing scopes.
3693 while E2
/= Standard_Standard
and then E2
/= WEnt
loop
3699 ("unlimited view visible through use clause ", W
);
3711 -- Recursive call to check all the ancestors
3713 if Is_Child_Spec
(Unit
(P
)) then
3714 Check_Renamings
(P
=> Parent_Spec
(Unit
(P
)), W
=> W
);
3716 end Check_Renamings
;
3718 ---------------------------------------
3719 -- Check_Private_Limited_Withed_Unit --
3720 ---------------------------------------
3722 procedure Check_Private_Limited_Withed_Unit
(Item
: Node_Id
) is
3723 Curr_Parent
: Node_Id
;
3724 Child_Parent
: Node_Id
;
3725 Curr_Private
: Boolean;
3728 -- Compilation unit of the parent of the withed library unit
3730 Child_Parent
:= Library_Unit
(Item
);
3732 -- If the child unit is a public child, then locate its nearest
3733 -- private ancestor, if any, then Child_Parent will then be set to
3734 -- the parent of that ancestor.
3736 if not Private_Present
(Library_Unit
(Item
)) then
3737 while Present
(Child_Parent
)
3738 and then not Private_Present
(Child_Parent
)
3740 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3743 if No
(Child_Parent
) then
3748 Child_Parent
:= Parent_Spec
(Unit
(Child_Parent
));
3750 -- Traverse all the ancestors of the current compilation unit to
3751 -- check if it is a descendant of named library unit.
3753 Curr_Parent
:= Parent
(Item
);
3754 Curr_Private
:= Private_Present
(Curr_Parent
);
3756 while Present
(Parent_Spec
(Unit
(Curr_Parent
)))
3757 and then Curr_Parent
/= Child_Parent
3759 Curr_Parent
:= Parent_Spec
(Unit
(Curr_Parent
));
3760 Curr_Private
:= Curr_Private
or else Private_Present
(Curr_Parent
);
3763 if Curr_Parent
/= Child_Parent
then
3765 ("unit in with clause is private child unit!", Item
);
3767 ("\current unit must also have parent&!",
3768 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3770 elsif Private_Present
(Parent
(Item
))
3771 or else Curr_Private
3772 or else Private_Present
(Item
)
3773 or else Nkind_In
(Unit
(Parent
(Item
)), N_Package_Body
,
3777 -- Current unit is private, of descendant of a private unit
3783 ("current unit must also be private descendant of&",
3784 Item
, Defining_Unit_Name
(Specification
(Unit
(Child_Parent
))));
3786 end Check_Private_Limited_Withed_Unit
;
3788 --------------------------------
3789 -- Expand_Limited_With_Clause --
3790 --------------------------------
3792 procedure Expand_Limited_With_Clause
3793 (Comp_Unit
: Node_Id
;
3797 Loc
: constant Source_Ptr
:= Sloc
(Nam
);
3798 Unum
: Unit_Number_Type
;
3801 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean;
3802 -- Returns true if the context already includes a with_clause for
3803 -- this unit. If the with_clause is non-limited, the unit is fully
3804 -- visible and an implicit limited_with should not be created. If
3805 -- there is already a limited_with clause for W, a second one is
3806 -- simply redundant.
3808 --------------------------
3809 -- Previous_Withed_Unit --
3810 --------------------------
3812 function Previous_Withed_Unit
(W
: Node_Id
) return Boolean is
3816 -- A limited with_clause cannot appear in the same context_clause
3817 -- as a nonlimited with_clause which mentions the same library.
3819 Item
:= First
(Context_Items
(Comp_Unit
));
3820 while Present
(Item
) loop
3821 if Nkind
(Item
) = N_With_Clause
3822 and then Library_Unit
(Item
) = Library_Unit
(W
)
3831 end Previous_Withed_Unit
;
3833 -- Start of processing for Expand_Limited_With_Clause
3836 if Nkind
(Nam
) = N_Identifier
then
3838 -- Create node for name of withed unit
3841 Make_With_Clause
(Loc
,
3842 Name
=> New_Copy
(Nam
));
3844 else pragma Assert
(Nkind
(Nam
) = N_Selected_Component
);
3846 Make_With_Clause
(Loc
,
3847 Name
=> Make_Selected_Component
(Loc
,
3848 Prefix
=> New_Copy_Tree
(Prefix
(Nam
)),
3849 Selector_Name
=> New_Copy
(Selector_Name
(Nam
))));
3850 Set_Parent
(Withn
, Parent
(N
));
3853 Set_Limited_Present
(Withn
);
3854 Set_First_Name
(Withn
);
3855 Set_Implicit_With
(Withn
);
3859 (Load_Name
=> Get_Spec_Name
(Get_Unit_Name
(Nam
)),
3864 -- Do not generate a limited_with_clause on the current unit. This
3865 -- path is taken when a unit has a limited_with clause on one of its
3868 if Unum
= Current_Sem_Unit
then
3872 Set_Library_Unit
(Withn
, Cunit
(Unum
));
3873 Set_Corresponding_Spec
3874 (Withn
, Specification
(Unit
(Cunit
(Unum
))));
3876 if not Previous_Withed_Unit
(Withn
) then
3877 Prepend
(Withn
, Context_Items
(Parent
(N
)));
3878 Mark_Rewrite_Insertion
(Withn
);
3880 -- Add implicit limited_with_clauses for parents of child units
3881 -- mentioned in limited_with clauses.
3883 if Nkind
(Nam
) = N_Selected_Component
then
3884 Expand_Limited_With_Clause
(Comp_Unit
, Prefix
(Nam
), N
);
3889 if not Limited_View_Installed
(Withn
) then
3890 Install_Limited_Withed_Unit
(Withn
);
3893 end Expand_Limited_With_Clause
;
3895 -- Start of processing for Install_Limited_Context_Clauses
3898 Item
:= First
(Context_Items
(N
));
3899 while Present
(Item
) loop
3900 if Nkind
(Item
) = N_With_Clause
3901 and then Limited_Present
(Item
)
3902 and then not Error_Posted
(Item
)
3904 if Nkind
(Name
(Item
)) = N_Selected_Component
then
3905 Expand_Limited_With_Clause
3906 (Comp_Unit
=> N
, Nam
=> Prefix
(Name
(Item
)), N
=> Item
);
3909 Check_Private_Limited_Withed_Unit
(Item
);
3911 if not Implicit_With
(Item
) and then Is_Child_Spec
(Unit
(N
)) then
3912 Check_Renamings
(Parent_Spec
(Unit
(N
)), Item
);
3915 -- A unit may have a limited with on itself if it has a limited
3916 -- with_clause on one of its child units. In that case it is
3917 -- already being compiled and it makes no sense to install its
3920 -- If the item is a limited_private_with_clause, install it if the
3921 -- current unit is a body or if it is a private child. Otherwise
3922 -- the private clause is installed before analyzing the private
3923 -- part of the current unit.
3925 if Library_Unit
(Item
) /= Cunit
(Current_Sem_Unit
)
3926 and then not Limited_View_Installed
(Item
)
3928 not Is_Ancestor_Unit
3929 (Library_Unit
(Item
), Cunit
(Current_Sem_Unit
))
3931 if not Private_Present
(Item
)
3932 or else Private_Present
(N
)
3933 or else Nkind_In
(Unit
(N
), N_Package_Body
,
3937 Install_Limited_Withed_Unit
(Item
);
3945 -- Ada 2005 (AI-412): Examine visible declarations of a package spec,
3946 -- looking for incomplete subtype declarations of incomplete types
3947 -- visible through a limited with clause.
3949 if Ada_Version
>= Ada_2005
3950 and then Analyzed
(N
)
3951 and then Nkind
(Unit
(N
)) = N_Package_Declaration
3956 Non_Lim_View
: Entity_Id
;
3959 Decl
:= First
(Visible_Declarations
(Specification
(Unit
(N
))));
3960 while Present
(Decl
) loop
3961 if Nkind
(Decl
) = N_Subtype_Declaration
3963 Ekind
(Defining_Identifier
(Decl
)) = E_Incomplete_Subtype
3965 From_Limited_With
(Defining_Identifier
(Decl
))
3967 Def_Id
:= Defining_Identifier
(Decl
);
3968 Non_Lim_View
:= Non_Limited_View
(Def_Id
);
3970 if not Is_Incomplete_Type
(Non_Lim_View
) then
3972 -- Convert an incomplete subtype declaration into a
3973 -- corresponding non-limited view subtype declaration.
3974 -- This is usually the case when analyzing a body that
3975 -- has regular with clauses, when the spec has limited
3978 -- If the non-limited view is still incomplete, it is
3979 -- the dummy entry already created, and the declaration
3980 -- cannot be reanalyzed. This is the case when installing
3981 -- a parent unit that has limited with-clauses.
3983 Set_Subtype_Indication
(Decl
,
3984 New_Occurrence_Of
(Non_Lim_View
, Sloc
(Def_Id
)));
3985 Set_Etype
(Def_Id
, Non_Lim_View
);
3986 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(Non_Lim_View
)));
3987 Set_Analyzed
(Decl
, False);
3989 -- Reanalyze the declaration, suppressing the call to
3990 -- Enter_Name to avoid duplicate names.
3992 Analyze_Subtype_Declaration
4002 end Install_Limited_Context_Clauses
;
4004 ---------------------
4005 -- Install_Parents --
4006 ---------------------
4008 procedure Install_Parents
(Lib_Unit
: Node_Id
; Is_Private
: Boolean) is
4015 P
:= Unit
(Parent_Spec
(Lib_Unit
));
4016 P_Name
:= Get_Parent_Entity
(P
);
4018 if Etype
(P_Name
) = Any_Type
then
4022 if Ekind
(P_Name
) = E_Generic_Package
4023 and then not Nkind_In
(Lib_Unit
, N_Generic_Subprogram_Declaration
,
4024 N_Generic_Package_Declaration
)
4025 and then Nkind
(Lib_Unit
) not in N_Generic_Renaming_Declaration
4028 ("child of a generic package must be a generic unit", Lib_Unit
);
4030 elsif not Is_Package_Or_Generic_Package
(P_Name
) then
4032 ("parent unit must be package or generic package", Lib_Unit
);
4033 raise Unrecoverable_Error
;
4035 elsif Present
(Renamed_Object
(P_Name
)) then
4036 Error_Msg_N
("parent unit cannot be a renaming", Lib_Unit
);
4037 raise Unrecoverable_Error
;
4039 -- Verify that a child of an instance is itself an instance, or the
4040 -- renaming of one. Given that an instance that is a unit is replaced
4041 -- with a package declaration, check against the original node. The
4042 -- parent may be currently being instantiated, in which case it appears
4043 -- as a declaration, but the generic_parent is already established
4044 -- indicating that we deal with an instance.
4046 elsif Nkind
(Original_Node
(P
)) = N_Package_Instantiation
then
4047 if Nkind
(Lib_Unit
) in N_Renaming_Declaration
4048 or else Nkind
(Original_Node
(Lib_Unit
)) in N_Generic_Instantiation
4050 (Nkind
(Lib_Unit
) = N_Package_Declaration
4051 and then Present
(Generic_Parent
(Specification
(Lib_Unit
))))
4056 ("child of an instance must be an instance or renaming",
4061 -- This is the recursive call that ensures all parents are loaded
4063 if Is_Child_Spec
(P
) then
4065 Is_Private
or else Private_Present
(Parent
(Lib_Unit
)));
4068 -- Now we can install the context for this parent
4070 Install_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4071 Install_Limited_Context_Clauses
(Parent_Spec
(Lib_Unit
));
4072 Install_Siblings
(P_Name
, Parent
(Lib_Unit
));
4074 -- The child unit is in the declarative region of the parent. The parent
4075 -- must therefore appear in the scope stack and be visible, as when
4076 -- compiling the corresponding body. If the child unit is private or it
4077 -- is a package body, private declarations must be accessible as well.
4078 -- Use declarations in the parent must also be installed. Finally, other
4079 -- child units of the same parent that are in the context are
4080 -- immediately visible.
4082 -- Find entity for compilation unit, and set its private descendant
4083 -- status as needed. Indicate that it is a compilation unit, which is
4084 -- redundant in general, but needed if this is a generated child spec
4085 -- for a child body without previous spec.
4087 E_Name
:= Defining_Entity
(Lib_Unit
);
4089 Set_Is_Child_Unit
(E_Name
);
4090 Set_Is_Compilation_Unit
(E_Name
);
4092 Set_Is_Private_Descendant
(E_Name
,
4093 Is_Private_Descendant
(P_Name
)
4094 or else Private_Present
(Parent
(Lib_Unit
)));
4096 P_Spec
:= Package_Specification
(P_Name
);
4097 Push_Scope
(P_Name
);
4099 -- Save current visibility of unit
4101 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
:=
4102 Is_Immediately_Visible
(P_Name
);
4103 Set_Is_Immediately_Visible
(P_Name
);
4104 Install_Visible_Declarations
(P_Name
);
4105 Set_Use
(Visible_Declarations
(P_Spec
));
4107 -- If the parent is a generic unit, its formal part may contain formal
4108 -- packages and use clauses for them.
4110 if Ekind
(P_Name
) = E_Generic_Package
then
4111 Set_Use
(Generic_Formal_Declarations
(Parent
(P_Spec
)));
4114 if Is_Private
or else Private_Present
(Parent
(Lib_Unit
)) then
4115 Install_Private_Declarations
(P_Name
);
4116 Install_Private_With_Clauses
(P_Name
);
4117 Set_Use
(Private_Declarations
(P_Spec
));
4119 end Install_Parents
;
4121 ----------------------------------
4122 -- Install_Private_With_Clauses --
4123 ----------------------------------
4125 procedure Install_Private_With_Clauses
(P
: Entity_Id
) is
4126 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
4130 if Debug_Flag_I
then
4131 Write_Str
("install private with clauses of ");
4132 Write_Name
(Chars
(P
));
4136 if Nkind
(Parent
(Decl
)) = N_Compilation_Unit
then
4137 Item
:= First
(Context_Items
(Parent
(Decl
)));
4138 while Present
(Item
) loop
4139 if Nkind
(Item
) = N_With_Clause
4140 and then Private_Present
(Item
)
4142 -- If the unit is an ancestor of the current one, it is the
4143 -- case of a private limited with clause on a child unit, and
4144 -- the compilation of one of its descendants, In that case the
4145 -- limited view is errelevant.
4147 if Limited_Present
(Item
) then
4148 if not Limited_View_Installed
(Item
)
4150 not Is_Ancestor_Unit
(Library_Unit
(Item
),
4151 Cunit
(Current_Sem_Unit
))
4153 Install_Limited_Withed_Unit
(Item
);
4156 Install_Withed_Unit
(Item
, Private_With_OK
=> True);
4163 end Install_Private_With_Clauses
;
4165 ----------------------
4166 -- Install_Siblings --
4167 ----------------------
4169 procedure Install_Siblings
(U_Name
: Entity_Id
; N
: Node_Id
) is
4175 -- Iterate over explicit with clauses, and check whether the scope of
4176 -- each entity is an ancestor of the current unit, in which case it is
4177 -- immediately visible.
4179 Item
:= First
(Context_Items
(N
));
4180 while Present
(Item
) loop
4182 -- Do not install private_with_clauses declaration, unless unit
4183 -- is itself a private child unit, or is a body. Note that for a
4184 -- subprogram body the private_with_clause does not take effect until
4185 -- after the specification.
4187 if Nkind
(Item
) /= N_With_Clause
4188 or else Implicit_With
(Item
)
4189 or else Limited_Present
(Item
)
4190 or else Error_Posted
(Item
)
4194 elsif not Private_Present
(Item
)
4195 or else Private_Present
(N
)
4196 or else Nkind
(Unit
(N
)) = N_Package_Body
4198 Id
:= Entity
(Name
(Item
));
4200 if Is_Child_Unit
(Id
)
4201 and then Is_Ancestor_Package
(Scope
(Id
), U_Name
)
4203 Set_Is_Immediately_Visible
(Id
);
4205 -- Check for the presence of another unit in the context that
4206 -- may be inadvertently hidden by the child.
4208 Prev
:= Current_Entity
(Id
);
4211 and then Is_Immediately_Visible
(Prev
)
4212 and then not Is_Child_Unit
(Prev
)
4218 Clause
:= First
(Context_Items
(N
));
4219 while Present
(Clause
) loop
4220 if Nkind
(Clause
) = N_With_Clause
4221 and then Entity
(Name
(Clause
)) = Prev
4224 ("child unit& hides compilation unit " &
4225 "with the same name??",
4235 -- The With_Clause may be on a grand-child or one of its further
4236 -- descendants, which makes a child immediately visible. Examine
4237 -- ancestry to determine whether such a child exists. For example,
4238 -- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
4239 -- is immediately visible.
4241 elsif Is_Child_Unit
(Id
) then
4247 while Is_Child_Unit
(Par
) loop
4248 if Is_Ancestor_Package
(Scope
(Par
), U_Name
) then
4249 Set_Is_Immediately_Visible
(Par
);
4258 -- If the item is a private with-clause on a child unit, the parent
4259 -- may have been installed already, but the child unit must remain
4260 -- invisible until installed in a private part or body, unless there
4261 -- is already a regular with_clause for it in the current unit.
4263 elsif Private_Present
(Item
) then
4264 Id
:= Entity
(Name
(Item
));
4266 if Is_Child_Unit
(Id
) then
4270 function In_Context
return Boolean;
4271 -- Scan context of current unit, to check whether there is
4272 -- a with_clause on the same unit as a private with-clause
4273 -- on a parent, in which case child unit is visible. If the
4274 -- unit is a grand-child, the same applies to its parent.
4280 function In_Context
return Boolean is
4283 First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4284 while Present
(Clause
) loop
4285 if Nkind
(Clause
) = N_With_Clause
4286 and then Comes_From_Source
(Clause
)
4287 and then Is_Entity_Name
(Name
(Clause
))
4288 and then not Private_Present
(Clause
)
4290 if Entity
(Name
(Clause
)) = Id
4292 (Nkind
(Name
(Clause
)) = N_Expanded_Name
4293 and then Entity
(Prefix
(Name
(Clause
))) = Id
)
4306 Set_Is_Visible_Lib_Unit
(Id
, In_Context
);
4313 end Install_Siblings
;
4315 ---------------------------------
4316 -- Install_Limited_Withed_Unit --
4317 ---------------------------------
4319 procedure Install_Limited_Withed_Unit
(N
: Node_Id
) is
4320 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
4323 Is_Child_Package
: Boolean := False;
4324 Lim_Header
: Entity_Id
;
4325 Lim_Typ
: Entity_Id
;
4327 procedure Check_Body_Required
;
4328 -- A unit mentioned in a limited with_clause may not be mentioned in
4329 -- a regular with_clause, but must still be included in the current
4330 -- partition. We need to determine whether the unit needs a body, so
4331 -- that the binder can determine the name of the file to be compiled.
4332 -- Checking whether a unit needs a body can be done without semantic
4333 -- analysis, by examining the nature of the declarations in the package.
4335 function Has_Limited_With_Clause
4336 (C_Unit
: Entity_Id
;
4337 Pack
: Entity_Id
) return Boolean;
4338 -- Determine whether any package in the ancestor chain starting with
4339 -- C_Unit has a limited with clause for package Pack.
4341 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean;
4342 -- Check if some package installed though normal with-clauses has a
4343 -- renaming declaration of package P. AARM 10.1.2(21/2).
4345 -------------------------
4346 -- Check_Body_Required --
4347 -------------------------
4349 procedure Check_Body_Required
is
4350 PA
: constant List_Id
:=
4351 Pragmas_After
(Aux_Decls_Node
(Parent
(P_Unit
)));
4353 procedure Check_Declarations
(Spec
: Node_Id
);
4354 -- Recursive procedure that does the work and checks nested packages
4356 ------------------------
4357 -- Check_Declarations --
4358 ------------------------
4360 procedure Check_Declarations
(Spec
: Node_Id
) is
4362 Incomplete_Decls
: constant Elist_Id
:= New_Elmt_List
;
4364 Subp_List
: constant Elist_Id
:= New_Elmt_List
;
4366 procedure Check_Pragma_Import
(P
: Node_Id
);
4367 -- If a pragma import applies to a previous subprogram, the
4368 -- enclosing unit may not need a body. The processing is syntactic
4369 -- and does not require a declaration to be analyzed. The code
4370 -- below also handles pragma Import when applied to a subprogram
4371 -- that renames another. In this case the pragma applies to the
4374 -- Chains of multiple renames are not handled by the code below.
4375 -- It is probably impossible to handle all cases without proper
4376 -- name resolution. In such cases the algorithm is conservative
4377 -- and will indicate that a body is needed???
4379 -------------------------
4380 -- Check_Pragma_Import --
4381 -------------------------
4383 procedure Check_Pragma_Import
(P
: Node_Id
) is
4389 procedure Remove_Homonyms
(E
: Node_Id
);
4390 -- Make one pass over list of subprograms. Called again if
4391 -- subprogram is a renaming. E is known to be an identifier.
4393 ---------------------
4394 -- Remove_Homonyms --
4395 ---------------------
4397 procedure Remove_Homonyms
(E
: Node_Id
) is
4398 R
: Entity_Id
:= Empty
;
4399 -- Name of renamed entity, if any
4402 Subp_Id
:= First_Elmt
(Subp_List
);
4403 while Present
(Subp_Id
) loop
4404 if Chars
(Node
(Subp_Id
)) = Chars
(E
) then
4405 if Nkind
(Parent
(Parent
(Node
(Subp_Id
))))
4406 /= N_Subprogram_Renaming_Declaration
4409 Next_Elmt
(Subp_Id
);
4410 Remove_Elmt
(Subp_List
, Prev_Id
);
4412 R
:= Name
(Parent
(Parent
(Node
(Subp_Id
))));
4416 Next_Elmt
(Subp_Id
);
4421 if Nkind
(R
) = N_Identifier
then
4422 Remove_Homonyms
(R
);
4424 elsif Nkind
(R
) = N_Selected_Component
then
4425 Remove_Homonyms
(Selector_Name
(R
));
4427 -- Renaming of attribute
4433 end Remove_Homonyms
;
4435 -- Start of processing for Check_Pragma_Import
4438 -- Find name of entity in Import pragma. We have not analyzed
4439 -- the construct, so we must guard against syntax errors.
4441 Arg
:= Next
(First
(Pragma_Argument_Associations
(P
)));
4444 or else Nkind
(Expression
(Arg
)) /= N_Identifier
4448 Imported
:= Expression
(Arg
);
4451 Remove_Homonyms
(Imported
);
4452 end Check_Pragma_Import
;
4454 -- Start of processing for Check_Declarations
4457 -- Search for Elaborate Body pragma
4459 Decl
:= First
(Visible_Declarations
(Spec
));
4460 while Present
(Decl
)
4461 and then Nkind
(Decl
) = N_Pragma
4463 if Get_Pragma_Id
(Decl
) = Pragma_Elaborate_Body
then
4464 Set_Body_Required
(Library_Unit
(N
));
4471 -- Look for declarations that require the presence of a body. We
4472 -- have already skipped pragmas at the start of the list.
4474 while Present
(Decl
) loop
4476 -- Subprogram that comes from source means body may be needed.
4477 -- Save for subsequent examination of import pragmas.
4479 if Comes_From_Source
(Decl
)
4480 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4481 N_Subprogram_Renaming_Declaration
,
4482 N_Generic_Subprogram_Declaration
))
4484 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4486 -- Package declaration of generic package declaration. We need
4487 -- to recursively examine nested declarations.
4489 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4490 N_Generic_Package_Declaration
)
4492 Check_Declarations
(Specification
(Decl
));
4494 elsif Nkind
(Decl
) = N_Pragma
4495 and then Pragma_Name
(Decl
) = Name_Import
4497 Check_Pragma_Import
(Decl
);
4503 -- Same set of tests for private part. In addition to subprograms
4504 -- detect the presence of Taft Amendment types (incomplete types
4505 -- completed in the body).
4507 Decl
:= First
(Private_Declarations
(Spec
));
4508 while Present
(Decl
) loop
4509 if Comes_From_Source
(Decl
)
4510 and then (Nkind_In
(Decl
, N_Subprogram_Declaration
,
4511 N_Subprogram_Renaming_Declaration
,
4512 N_Generic_Subprogram_Declaration
))
4514 Append_Elmt
(Defining_Entity
(Decl
), Subp_List
);
4516 elsif Nkind_In
(Decl
, N_Package_Declaration
,
4517 N_Generic_Package_Declaration
)
4519 Check_Declarations
(Specification
(Decl
));
4521 -- Collect incomplete type declarations for separate pass
4523 elsif Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
4524 Append_Elmt
(Decl
, Incomplete_Decls
);
4526 elsif Nkind
(Decl
) = N_Pragma
4527 and then Pragma_Name
(Decl
) = Name_Import
4529 Check_Pragma_Import
(Decl
);
4535 -- Now check incomplete declarations to locate Taft amendment
4536 -- types. This can be done by examining the defining identifiers
4537 -- of type declarations without real semantic analysis.
4543 Inc
:= First_Elmt
(Incomplete_Decls
);
4544 while Present
(Inc
) loop
4545 Decl
:= Next
(Node
(Inc
));
4546 while Present
(Decl
) loop
4547 if Nkind
(Decl
) = N_Full_Type_Declaration
4548 and then Chars
(Defining_Identifier
(Decl
)) =
4549 Chars
(Defining_Identifier
(Node
(Inc
)))
4557 -- If no completion, this is a TAT, and a body is needed
4560 Set_Body_Required
(Library_Unit
(N
));
4568 -- Finally, check whether there are subprograms that still require
4569 -- a body, i.e. are not renamings or null.
4571 if not Is_Empty_Elmt_List
(Subp_List
) then
4577 Subp_Id
:= First_Elmt
(Subp_List
);
4578 Spec
:= Parent
(Node
(Subp_Id
));
4580 while Present
(Subp_Id
) loop
4581 if Nkind
(Parent
(Spec
))
4582 = N_Subprogram_Renaming_Declaration
4586 elsif Nkind
(Spec
) = N_Procedure_Specification
4587 and then Null_Present
(Spec
)
4592 Set_Body_Required
(Library_Unit
(N
));
4596 Next_Elmt
(Subp_Id
);
4600 end Check_Declarations
;
4602 -- Start of processing for Check_Body_Required
4605 -- If this is an imported package (Java and CIL usage) no body is
4606 -- needed. Scan list of pragmas that may follow a compilation unit
4607 -- to look for a relevant pragma Import.
4609 if Present
(PA
) then
4615 while Present
(Prag
) loop
4616 if Nkind
(Prag
) = N_Pragma
4617 and then Get_Pragma_Id
(Prag
) = Pragma_Import
4627 Check_Declarations
(Specification
(P_Unit
));
4628 end Check_Body_Required
;
4630 -----------------------------
4631 -- Has_Limited_With_Clause --
4632 -----------------------------
4634 function Has_Limited_With_Clause
4635 (C_Unit
: Entity_Id
;
4636 Pack
: Entity_Id
) return Boolean
4643 while Present
(Par
) loop
4644 if Ekind
(Par
) /= E_Package
then
4648 -- Retrieve the Compilation_Unit node for Par and determine if
4649 -- its context clauses contain a limited with for Pack.
4651 Par_Unit
:= Parent
(Parent
(Parent
(Par
)));
4653 if Nkind
(Par_Unit
) = N_Package_Declaration
then
4654 Par_Unit
:= Parent
(Par_Unit
);
4657 if Has_With_Clause
(Par_Unit
, Pack
, True) then
4661 -- If there are more ancestors, climb up the tree, otherwise we
4664 if Is_Child_Unit
(Par
) then
4672 end Has_Limited_With_Clause
;
4674 ----------------------------------
4675 -- Is_Visible_Through_Renamings --
4676 ----------------------------------
4678 function Is_Visible_Through_Renamings
(P
: Entity_Id
) return Boolean is
4679 Kind
: constant Node_Kind
:=
4680 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)));
4686 -- Example of the error detected by this subprogram:
4694 -- package Ren_P renames P;
4700 -- limited with P; -- ERROR
4701 -- package R.C is ...
4703 Aux_Unit
:= Cunit
(Current_Sem_Unit
);
4706 Item
:= First
(Context_Items
(Aux_Unit
));
4707 while Present
(Item
) loop
4708 if Nkind
(Item
) = N_With_Clause
4709 and then not Limited_Present
(Item
)
4710 and then Nkind
(Unit
(Library_Unit
(Item
))) =
4711 N_Package_Declaration
4714 First
(Visible_Declarations
4715 (Specification
(Unit
(Library_Unit
(Item
)))));
4716 while Present
(Decl
) loop
4717 if Nkind
(Decl
) = N_Package_Renaming_Declaration
4718 and then Entity
(Name
(Decl
)) = P
4720 -- Generate the error message only if the current unit
4721 -- is a package declaration; in case of subprogram
4722 -- bodies and package bodies we just return True to
4723 -- indicate that the limited view must not be
4726 if Kind
= N_Package_Declaration
then
4728 ("simultaneous visibility of the limited and " &
4729 "unlimited views not allowed", N
);
4730 Error_Msg_Sloc
:= Sloc
(Item
);
4732 ("\\ unlimited view of & visible through the " &
4733 "context clause #", N
, P
);
4734 Error_Msg_Sloc
:= Sloc
(Decl
);
4735 Error_Msg_NE
("\\ and the renaming #", N
, P
);
4748 -- If it is a body not acting as spec, follow pointer to the
4749 -- corresponding spec, otherwise follow pointer to parent spec.
4751 if Present
(Library_Unit
(Aux_Unit
))
4752 and then Nkind_In
(Unit
(Aux_Unit
),
4753 N_Package_Body
, N_Subprogram_Body
)
4755 if Aux_Unit
= Library_Unit
(Aux_Unit
) then
4757 -- Aux_Unit is a body that acts as a spec. Clause has
4758 -- already been flagged as illegal.
4763 Aux_Unit
:= Library_Unit
(Aux_Unit
);
4767 Aux_Unit
:= Parent_Spec
(Unit
(Aux_Unit
));
4770 exit when No
(Aux_Unit
);
4774 end Is_Visible_Through_Renamings
;
4776 -- Start of processing for Install_Limited_Withed_Unit
4779 pragma Assert
(not Limited_View_Installed
(N
));
4781 -- In case of limited with_clause on subprograms, generics, instances,
4782 -- or renamings, the corresponding error was previously posted and we
4783 -- have nothing to do here. If the file is missing altogether, it has
4784 -- no source location.
4786 if Nkind
(P_Unit
) /= N_Package_Declaration
4787 or else Sloc
(P_Unit
) = No_Location
4792 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
4794 -- Handle child packages
4796 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
4797 Is_Child_Package
:= True;
4798 P
:= Defining_Identifier
(P
);
4801 -- Do not install the limited-view if the context of the unit is already
4802 -- available through a regular with clause.
4804 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4805 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4810 -- Do not install the limited-view if the full-view is already visible
4811 -- through renaming declarations.
4813 if Is_Visible_Through_Renamings
(P
) then
4817 -- Do not install the limited view if this is the unit being analyzed.
4818 -- This unusual case will happen when a unit has a limited_with clause
4819 -- on one of its children. The compilation of the child forces the load
4820 -- of the parent which tries to install the limited view of the child
4821 -- again. Installing the limited view must also be disabled when
4822 -- compiling the body of the child unit.
4824 if P
= Cunit_Entity
(Current_Sem_Unit
)
4825 or else (Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4826 and then P
= Main_Unit_Entity
4827 and then Is_Ancestor_Unit
4828 (Cunit
(Main_Unit
), Cunit
(Current_Sem_Unit
)))
4833 -- This scenario is similar to the one above, the difference is that the
4834 -- compilation of sibling Par.Sib forces the load of parent Par which
4835 -- tries to install the limited view of Lim_Pack [1]. However Par.Sib
4836 -- has a with clause for Lim_Pack [2] in its body, and thus needs the
4837 -- non-limited views of all entities from Lim_Pack.
4839 -- limited with Lim_Pack; -- [1]
4840 -- package Par is ... package Lim_Pack is ...
4842 -- with Lim_Pack; -- [2]
4843 -- package Par.Sib is ... package body Par.Sib is ...
4845 -- In this case Main_Unit_Entity is the spec of Par.Sib and Current_
4846 -- Sem_Unit is the body of Par.Sib.
4848 if Ekind
(P
) = E_Package
4849 and then Ekind
(Main_Unit_Entity
) = E_Package
4850 and then Is_Child_Unit
(Main_Unit_Entity
)
4852 -- The body has a regular with clause
4854 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
4855 and then Has_With_Clause
(Cunit
(Current_Sem_Unit
), P
)
4857 -- One of the ancestors has a limited with clause
4859 and then Nkind
(Parent
(Parent
(Main_Unit_Entity
))) =
4860 N_Package_Specification
4861 and then Has_Limited_With_Clause
(Scope
(Main_Unit_Entity
), P
)
4866 -- A common use of the limited-with is to have a limited-with in the
4867 -- package spec, and a normal with in its package body. For example:
4869 -- limited with X; -- [1]
4873 -- package body A is ...
4875 -- The compilation of A's body installs the context clauses found at [2]
4876 -- and then the context clauses of its specification (found at [1]). As
4877 -- a consequence, at [1] the specification of X has been analyzed and it
4878 -- is immediately visible. According to the semantics of limited-with
4879 -- context clauses we don't install the limited view because the full
4880 -- view of X supersedes its limited view.
4882 if Analyzed
(P_Unit
)
4884 (Is_Immediately_Visible
(P
)
4885 or else (Is_Child_Package
and then Is_Visible_Lib_Unit
(P
)))
4888 -- The presence of both the limited and the analyzed nonlimited view
4889 -- may also be an error, such as an illegal context for a limited
4890 -- with_clause. In that case, do not process the context item at all.
4892 if Error_Posted
(N
) then
4896 if Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
4900 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
4901 while Present
(Item
) loop
4902 if Nkind
(Item
) = N_With_Clause
4903 and then Comes_From_Source
(Item
)
4904 and then Entity
(Name
(Item
)) = P
4913 -- If this is a child body, assume that the nonlimited with_clause
4914 -- appears in an ancestor. Could be refined ???
4918 (Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)))))
4925 -- If in package declaration, nonlimited view brought in from
4926 -- parent unit or some error condition.
4932 if Debug_Flag_I
then
4933 Write_Str
("install limited view of ");
4934 Write_Name
(Chars
(P
));
4938 -- If the unit has not been analyzed and the limited view has not been
4939 -- already installed then we install it.
4941 if not Analyzed
(P_Unit
) then
4942 if not In_Chain
(P
) then
4944 -- Minimum decoration
4946 Set_Ekind
(P
, E_Package
);
4947 Set_Etype
(P
, Standard_Void_Type
);
4948 Set_Scope
(P
, Standard_Standard
);
4949 Set_Is_Visible_Lib_Unit
(P
);
4951 if Is_Child_Package
then
4952 Set_Is_Child_Unit
(P
);
4953 Set_Scope
(P
, Defining_Entity
(Unit
(Parent_Spec
(P_Unit
))));
4956 -- Place entity on visibility structure
4958 Set_Homonym
(P
, Current_Entity
(P
));
4959 Set_Current_Entity
(P
);
4961 if Debug_Flag_I
then
4962 Write_Str
(" (homonym) chain ");
4963 Write_Name
(Chars
(P
));
4967 -- Install the incomplete view. The first element of the limited
4968 -- view is a header (an E_Package entity) used to reference the
4969 -- first shadow entity in the private part of the package.
4971 Lim_Header
:= Limited_View
(P
);
4972 Lim_Typ
:= First_Entity
(Lim_Header
);
4974 while Present
(Lim_Typ
)
4975 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
4977 Set_Homonym
(Lim_Typ
, Current_Entity
(Lim_Typ
));
4978 Set_Current_Entity
(Lim_Typ
);
4980 if Debug_Flag_I
then
4981 Write_Str
(" (homonym) chain ");
4982 Write_Name
(Chars
(Lim_Typ
));
4986 Next_Entity
(Lim_Typ
);
4990 -- If the unit appears in a previous regular with_clause, the regular
4991 -- entities of the public part of the withed package must be replaced
4992 -- by the shadow ones.
4994 -- This code must be kept synchronized with the code that replaces the
4995 -- shadow entities by the real entities (see body of Remove_Limited
4996 -- With_Clause); otherwise the contents of the homonym chains are not
5000 -- Hide all the type entities of the public part of the package to
5001 -- avoid its usage. This is needed to cover all the subtype decla-
5002 -- rations because we do not remove them from the homonym chain.
5004 E
:= First_Entity
(P
);
5005 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
5007 Set_Was_Hidden
(E
, Is_Hidden
(E
));
5014 -- Replace the real entities by the shadow entities of the limited
5015 -- view. The first element of the limited view is a header that is
5016 -- used to reference the first shadow entity in the private part
5017 -- of the package. Successive elements are the limited views of the
5018 -- type (including regular incomplete types) declared in the package.
5020 Lim_Header
:= Limited_View
(P
);
5022 Lim_Typ
:= First_Entity
(Lim_Header
);
5023 while Present
(Lim_Typ
)
5024 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
5026 pragma Assert
(not In_Chain
(Lim_Typ
));
5028 -- Do not unchain nested packages and child units
5030 if Ekind
(Lim_Typ
) /= E_Package
5031 and then not Is_Child_Unit
(Lim_Typ
)
5037 Prev
:= Current_Entity
(Lim_Typ
);
5040 -- Replace E in the homonyms list, so that the limited view
5041 -- becomes available.
5043 -- If the non-limited view is a record with an anonymous
5044 -- self-referential component, the analysis of the record
5045 -- declaration creates an incomplete type with the same name
5046 -- in order to define an internal access type. The visible
5047 -- entity is now the incomplete type, and that is the one to
5048 -- replace in the visibility structure.
5050 if E
= Non_Limited_View
(Lim_Typ
)
5052 (Ekind
(E
) = E_Incomplete_Type
5053 and then Full_View
(E
) = Non_Limited_View
(Lim_Typ
))
5055 Set_Homonym
(Lim_Typ
, Homonym
(Prev
));
5056 Set_Current_Entity
(Lim_Typ
);
5060 E
:= Homonym
(Prev
);
5062 -- E may have been removed when installing a previous
5063 -- limited_with_clause.
5066 exit when E
= Non_Limited_View
(Lim_Typ
);
5067 Prev
:= Homonym
(Prev
);
5071 Set_Homonym
(Lim_Typ
, Homonym
(Homonym
(Prev
)));
5072 Set_Homonym
(Prev
, Lim_Typ
);
5077 if Debug_Flag_I
then
5078 Write_Str
(" (homonym) chain ");
5079 Write_Name
(Chars
(Lim_Typ
));
5084 Next_Entity
(Lim_Typ
);
5088 -- The package must be visible while the limited-with clause is active
5089 -- because references to the type P.T must resolve in the usual way.
5090 -- In addition, we remember that the limited-view has been installed to
5091 -- uninstall it at the point of context removal.
5093 Set_Is_Immediately_Visible
(P
);
5094 Set_Limited_View_Installed
(N
);
5096 -- If unit has not been analyzed in some previous context, check
5097 -- (imperfectly ???) whether it might need a body.
5099 if not Analyzed
(P_Unit
) then
5100 Check_Body_Required
;
5103 -- If the package in the limited_with clause is a child unit, the clause
5104 -- is unanalyzed and appears as a selected component. Recast it as an
5105 -- expanded name so that the entity can be properly set. Use entity of
5106 -- parent, if available, for higher ancestors in the name.
5108 if Nkind
(Name
(N
)) = N_Selected_Component
then
5116 while Nkind
(Nam
) = N_Selected_Component
5117 and then Present
(Ent
)
5119 Change_Selected_Component_To_Expanded_Name
(Nam
);
5121 -- Set entity of parent identifiers if the unit is a child
5122 -- unit. This ensures that the tree is properly formed from
5123 -- semantic point of view (e.g. for ASIS queries). The unit
5124 -- entities are not fully analyzed, so we need to follow unit
5125 -- links in the tree.
5127 Set_Entity
(Nam
, Ent
);
5129 Nam
:= Prefix
(Nam
);
5132 (Unit
(Parent_Spec
(Unit_Declaration_Node
(Ent
))));
5134 -- Set entity of last ancestor
5136 if Nkind
(Nam
) = N_Identifier
then
5137 Set_Entity
(Nam
, Ent
);
5143 Set_Entity
(Name
(N
), P
);
5144 Set_From_Limited_With
(P
);
5145 end Install_Limited_Withed_Unit
;
5147 -------------------------
5148 -- Install_Withed_Unit --
5149 -------------------------
5151 procedure Install_Withed_Unit
5152 (With_Clause
: Node_Id
;
5153 Private_With_OK
: Boolean := False)
5155 Uname
: constant Entity_Id
:= Entity
(Name
(With_Clause
));
5156 P
: constant Entity_Id
:= Scope
(Uname
);
5159 -- Ada 2005 (AI-262): Do not install the private withed unit if we are
5160 -- compiling a package declaration and the Private_With_OK flag was not
5161 -- set by the caller. These declarations will be installed later (before
5162 -- analyzing the private part of the package).
5164 if Private_Present
(With_Clause
)
5165 and then Nkind
(Unit
(Parent
(With_Clause
))) = N_Package_Declaration
5166 and then not (Private_With_OK
)
5171 if Debug_Flag_I
then
5172 if Private_Present
(With_Clause
) then
5173 Write_Str
("install private withed unit ");
5175 Write_Str
("install withed unit ");
5178 Write_Name
(Chars
(Uname
));
5182 -- We do not apply the restrictions to an internal unit unless we are
5183 -- compiling the internal unit as a main unit. This check is also
5184 -- skipped for dummy units (for missing packages).
5186 if Sloc
(Uname
) /= No_Location
5187 and then (not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
5188 or else Current_Sem_Unit
= Main_Unit
)
5190 Check_Restricted_Unit
5191 (Unit_Name
(Get_Source_Unit
(Uname
)), With_Clause
);
5194 if P
/= Standard_Standard
then
5196 -- If the unit is not analyzed after analysis of the with clause and
5197 -- it is an instantiation then it awaits a body and is the main unit.
5198 -- Its appearance in the context of some other unit indicates a
5199 -- circular dependency (DEC suite perversity).
5201 if not Analyzed
(Uname
)
5202 and then Nkind
(Parent
(Uname
)) = N_Package_Instantiation
5205 ("instantiation depends on itself", Name
(With_Clause
));
5207 elsif not Is_Visible_Lib_Unit
(Uname
) then
5209 -- Abandon processing in case of previous errors
5211 if No
(Scope
(Uname
)) then
5212 Check_Error_Detected
;
5216 Set_Is_Visible_Lib_Unit
(Uname
);
5218 -- If the unit is a wrapper package for a compilation unit that is
5219 -- a subprogrm instance, indicate that the instance itself is a
5220 -- visible unit. This is necessary if the instance is inlined.
5222 if Is_Wrapper_Package
(Uname
) then
5223 Set_Is_Visible_Lib_Unit
(Related_Instance
(Uname
));
5226 -- If the child unit appears in the context of its parent, it is
5227 -- immediately visible.
5229 if In_Open_Scopes
(Scope
(Uname
)) then
5230 Set_Is_Immediately_Visible
(Uname
);
5233 if Is_Generic_Instance
(Uname
)
5234 and then Ekind
(Uname
) in Subprogram_Kind
5236 -- Set flag as well on the visible entity that denotes the
5237 -- instance, which renames the current one.
5239 Set_Is_Visible_Lib_Unit
5241 (Defining_Entity
(Unit
(Library_Unit
(With_Clause
)))));
5244 -- The parent unit may have been installed already, and may have
5245 -- appeared in a use clause.
5247 if In_Use
(Scope
(Uname
)) then
5248 Set_Is_Potentially_Use_Visible
(Uname
);
5251 Set_Context_Installed
(With_Clause
);
5254 elsif not Is_Immediately_Visible
(Uname
) then
5255 Set_Is_Visible_Lib_Unit
(Uname
);
5257 if not Private_Present
(With_Clause
) or else Private_With_OK
then
5258 Set_Is_Immediately_Visible
(Uname
);
5261 Set_Context_Installed
(With_Clause
);
5264 -- A with-clause overrides a with-type clause: there are no restric-
5265 -- tions on the use of package entities.
5267 if Ekind
(Uname
) = E_Package
then
5268 Set_From_Limited_With
(Uname
, False);
5271 -- Ada 2005 (AI-377): it is illegal for a with_clause to name a child
5272 -- unit if there is a visible homograph for it declared in the same
5273 -- declarative region. This pathological case can only arise when an
5274 -- instance I1 of a generic unit G1 has an explicit child unit I1.G2,
5275 -- G1 has a generic child also named G2, and the context includes with_
5276 -- clauses for both I1.G2 and for G1.G2, making an implicit declaration
5277 -- of I1.G2 visible as well. If the child unit is named Standard, do
5278 -- not apply the check to the Standard package itself.
5280 if Is_Child_Unit
(Uname
)
5281 and then Is_Visible_Lib_Unit
(Uname
)
5282 and then Ada_Version
>= Ada_2005
5285 Decl1
: constant Node_Id
:= Unit_Declaration_Node
(P
);
5291 U2
:= Homonym
(Uname
);
5292 while Present
(U2
) and then U2
/= Standard_Standard
loop
5294 Decl2
:= Unit_Declaration_Node
(P2
);
5296 if Is_Child_Unit
(U2
) and then Is_Visible_Lib_Unit
(U2
) then
5297 if Is_Generic_Instance
(P
)
5298 and then Nkind
(Decl1
) = N_Package_Declaration
5299 and then Generic_Parent
(Specification
(Decl1
)) = P2
5301 Error_Msg_N
("illegal with_clause", With_Clause
);
5303 ("\child unit has visible homograph" &
5304 " (RM 8.3(26), 10.1.1(19))",
5308 elsif Is_Generic_Instance
(P2
)
5309 and then Nkind
(Decl2
) = N_Package_Declaration
5310 and then Generic_Parent
(Specification
(Decl2
)) = P
5312 -- With_clause for child unit of instance appears before
5313 -- in the context. We want to place the error message on
5314 -- it, not on the generic child unit itself.
5317 Prev_Clause
: Node_Id
;
5320 Prev_Clause
:= First
(List_Containing
(With_Clause
));
5321 while Entity
(Name
(Prev_Clause
)) /= U2
loop
5325 pragma Assert
(Present
(Prev_Clause
));
5326 Error_Msg_N
("illegal with_clause", Prev_Clause
);
5328 ("\child unit has visible homograph" &
5329 " (RM 8.3(26), 10.1.1(19))",
5340 end Install_Withed_Unit
;
5346 function Is_Child_Spec
(Lib_Unit
: Node_Id
) return Boolean is
5347 K
: constant Node_Kind
:= Nkind
(Lib_Unit
);
5350 return (K
in N_Generic_Declaration
or else
5351 K
in N_Generic_Instantiation
or else
5352 K
in N_Generic_Renaming_Declaration
or else
5353 K
= N_Package_Declaration
or else
5354 K
= N_Package_Renaming_Declaration
or else
5355 K
= N_Subprogram_Declaration
or else
5356 K
= N_Subprogram_Renaming_Declaration
)
5357 and then Present
(Parent_Spec
(Lib_Unit
));
5360 ------------------------------------
5361 -- Is_Legal_Shadow_Entity_In_Body --
5362 ------------------------------------
5364 function Is_Legal_Shadow_Entity_In_Body
(T
: Entity_Id
) return Boolean is
5365 C_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5367 return Nkind
(Unit
(C_Unit
)) = N_Package_Body
5370 (C_Unit
, Cunit_Entity
(Get_Source_Unit
(Non_Limited_View
(T
))));
5371 end Is_Legal_Shadow_Entity_In_Body
;
5373 ----------------------
5374 -- Is_Ancestor_Unit --
5375 ----------------------
5377 function Is_Ancestor_Unit
(U1
: Node_Id
; U2
: Node_Id
) return Boolean is
5378 E1
: constant Entity_Id
:= Defining_Entity
(Unit
(U1
));
5381 if Nkind_In
(Unit
(U2
), N_Package_Body
, N_Subprogram_Body
) then
5382 E2
:= Defining_Entity
(Unit
(Library_Unit
(U2
)));
5383 return Is_Ancestor_Package
(E1
, E2
);
5387 end Is_Ancestor_Unit
;
5389 -----------------------
5390 -- Load_Needed_Body --
5391 -----------------------
5393 -- N is a generic unit named in a with clause, or else it is a unit that
5394 -- contains a generic unit or an inlined function. In order to perform an
5395 -- instantiation, the body of the unit must be present. If the unit itself
5396 -- is generic, we assume that an instantiation follows, and load & analyze
5397 -- the body unconditionally. This forces analysis of the spec as well.
5399 -- If the unit is not generic, but contains a generic unit, it is loaded on
5400 -- demand, at the point of instantiation (see ch12).
5402 procedure Load_Needed_Body
5405 Do_Analyze
: Boolean := True)
5407 Body_Name
: Unit_Name_Type
;
5408 Unum
: Unit_Number_Type
;
5410 Save_Style_Check
: constant Boolean := Opt
.Style_Check
;
5411 -- The loading and analysis is done with style checks off
5414 if not GNAT_Mode
then
5415 Style_Check
:= False;
5418 Body_Name
:= Get_Body_Name
(Get_Unit_Name
(Unit
(N
)));
5421 (Load_Name
=> Body_Name
,
5427 if Unum
= No_Unit
then
5431 Compiler_State
:= Analyzing
; -- reset after load
5433 if not Fatal_Error
(Unum
) or else Try_Semantics
then
5434 if Debug_Flag_L
then
5435 Write_Str
("*** Loaded generic body");
5440 Semantics
(Cunit
(Unum
));
5447 Style_Check
:= Save_Style_Check
;
5448 end Load_Needed_Body
;
5450 -------------------------
5451 -- Build_Limited_Views --
5452 -------------------------
5454 procedure Build_Limited_Views
(N
: Node_Id
) is
5455 Unum
: constant Unit_Number_Type
:=
5456 Get_Source_Unit
(Library_Unit
(N
));
5457 Is_Analyzed
: constant Boolean := Analyzed
(Cunit
(Unum
));
5459 Shadow_Pack
: Entity_Id
;
5460 -- The corresponding shadow entity of the withed package. This entity
5461 -- offers incomplete views of packages and types as well as abstract
5462 -- views of states and variables declared within.
5464 Last_Shadow
: Entity_Id
:= Empty
;
5465 -- The last shadow entity created by routine Build_Shadow_Entity
5467 procedure Build_Shadow_Entity
5470 Shadow
: out Entity_Id
;
5471 Is_Tagged
: Boolean := False);
5472 -- Create a shadow entity that hides Ent and offers an abstract or
5473 -- incomplete view of Ent. Scop is the proper scope. Flag Is_Tagged
5474 -- should be set when Ent is a tagged type. The generated entity is
5475 -- added to Lim_Header. This routine updates the value of Last_Shadow.
5477 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5478 -- Perform minimal decoration of a package or its corresponding shadow
5479 -- entity denoted by Ent. Scop is the proper scope.
5481 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5482 -- Perform full decoration of an abstract state or its corresponding
5483 -- shadow entity denoted by Ent. Scop is the proper scope.
5485 procedure Decorate_Type
5488 Is_Tagged
: Boolean := False;
5489 Materialize
: Boolean := False);
5490 -- Perform minimal decoration of a type or its corresponding shadow
5491 -- entity denoted by Ent. Scop is the proper scope. Flag Is_Tagged
5492 -- should be set when Ent is a tagged type. Flag Materialize should be
5493 -- set when Ent is a tagged type and its class-wide type needs to appear
5496 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
);
5497 -- Perform minimal decoration of a variable denoted by Ent. Scop is the
5500 procedure Process_Declarations_And_States
5504 Create_Abstract_Views
: Boolean);
5505 -- Inspect the states of package Pack and declarative list Decls. Create
5506 -- shadow entities for all nested packages, states, types and variables
5507 -- encountered. Scop is the proper scope. Create_Abstract_Views should
5508 -- be set when the abstract states and variables need to be processed.
5510 -------------------------
5511 -- Build_Shadow_Entity --
5512 -------------------------
5514 procedure Build_Shadow_Entity
5517 Shadow
: out Entity_Id
;
5518 Is_Tagged
: Boolean := False)
5521 Shadow
:= Make_Temporary
(Sloc
(Ent
), 'Z');
5523 -- The shadow entity must share the same name and parent as the
5526 Set_Chars
(Shadow
, Chars
(Ent
));
5527 Set_Parent
(Shadow
, Parent
(Ent
));
5529 -- The abstract view of a variable is a state, not another variable
5531 if Ekind
(Ent
) = E_Variable
then
5532 Set_Ekind
(Shadow
, E_Abstract_State
);
5534 Set_Ekind
(Shadow
, Ekind
(Ent
));
5537 Set_Is_Internal
(Shadow
);
5538 Set_From_Limited_With
(Shadow
);
5540 -- Add the new shadow entity to the limited view of the package
5542 Last_Shadow
:= Shadow
;
5543 Append_Entity
(Shadow
, Shadow_Pack
);
5545 -- Perform context-specific decoration of the shadow entity
5547 if Ekind
(Ent
) = E_Abstract_State
then
5548 Decorate_State
(Shadow
, Scop
);
5549 Set_Non_Limited_View
(Shadow
, Ent
);
5551 elsif Ekind
(Ent
) = E_Package
then
5552 Decorate_Package
(Shadow
, Scop
);
5554 elsif Is_Type
(Ent
) then
5555 Decorate_Type
(Shadow
, Scop
, Is_Tagged
);
5556 Set_Non_Limited_View
(Shadow
, Ent
);
5558 if Is_Incomplete_Or_Private_Type
(Ent
) then
5559 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
5562 elsif Ekind
(Ent
) = E_Variable
then
5563 Decorate_State
(Shadow
, Scop
);
5564 Set_Non_Limited_View
(Shadow
, Ent
);
5566 end Build_Shadow_Entity
;
5568 ----------------------
5569 -- Decorate_Package --
5570 ----------------------
5572 procedure Decorate_Package
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5574 Set_Ekind
(Ent
, E_Package
);
5575 Set_Etype
(Ent
, Standard_Void_Type
);
5576 Set_Scope
(Ent
, Scop
);
5577 end Decorate_Package
;
5579 --------------------
5580 -- Decorate_State --
5581 --------------------
5583 procedure Decorate_State
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5585 Set_Ekind
(Ent
, E_Abstract_State
);
5586 Set_Etype
(Ent
, Standard_Void_Type
);
5587 Set_Scope
(Ent
, Scop
);
5588 Set_Encapsulating_State
(Ent
, Empty
);
5589 Set_Refinement_Constituents
(Ent
, New_Elmt_List
);
5590 Set_Part_Of_Constituents
(Ent
, New_Elmt_List
);
5597 procedure Decorate_Type
5600 Is_Tagged
: Boolean := False;
5601 Materialize
: Boolean := False)
5606 -- An unanalyzed type or a shadow entity of a type is treated as an
5609 Set_Ekind
(Ent
, E_Incomplete_Type
);
5610 Set_Etype
(Ent
, Ent
);
5611 Set_Scope
(Ent
, Scop
);
5612 Set_Is_First_Subtype
(Ent
);
5613 Set_Stored_Constraint
(Ent
, No_Elist
);
5614 Set_Full_View
(Ent
, Empty
);
5615 Init_Size_Align
(Ent
);
5617 -- A tagged type and its corresponding shadow entity share one common
5621 Set_Is_Tagged_Type
(Ent
);
5623 if No
(Class_Wide_Type
(Ent
)) then
5626 (E_Void
, Scope
(Ent
), Sloc
(Ent
), Ent
, 'C', 0, 'T');
5628 Set_Class_Wide_Type
(Ent
, CW_Typ
);
5630 -- Set parent to be the same as the parent of the tagged type.
5631 -- We need a parent field set, and it is supposed to point to
5632 -- the declaration of the type. The tagged type declaration
5633 -- essentially declares two separate types, the tagged type
5634 -- itself and the corresponding class-wide type, so it is
5635 -- reasonable for the parent fields to point to the declaration
5638 Set_Parent
(CW_Typ
, Parent
(Ent
));
5640 Set_Ekind
(CW_Typ
, E_Class_Wide_Type
);
5641 Set_Etype
(CW_Typ
, Ent
);
5642 Set_Scope
(CW_Typ
, Scop
);
5643 Set_Is_Tagged_Type
(CW_Typ
);
5644 Set_Is_First_Subtype
(CW_Typ
);
5645 Init_Size_Align
(CW_Typ
);
5646 Set_Has_Unknown_Discriminants
(CW_Typ
);
5647 Set_Class_Wide_Type
(CW_Typ
, CW_Typ
);
5648 Set_Equivalent_Type
(CW_Typ
, Empty
);
5649 Set_From_Limited_With
(CW_Typ
, From_Limited_With
(Ent
));
5650 Set_Materialize_Entity
(CW_Typ
, Materialize
);
5655 -----------------------
5656 -- Decorate_Variable --
5657 -----------------------
5659 procedure Decorate_Variable
(Ent
: Entity_Id
; Scop
: Entity_Id
) is
5661 Set_Ekind
(Ent
, E_Variable
);
5662 Set_Etype
(Ent
, Standard_Void_Type
);
5663 Set_Scope
(Ent
, Scop
);
5664 end Decorate_Variable
;
5666 -------------------------------------
5667 -- Process_Declarations_And_States --
5668 -------------------------------------
5670 procedure Process_Declarations_And_States
5674 Create_Abstract_Views
: Boolean)
5676 procedure Find_And_Process_States
;
5677 -- Determine whether package Pack defines abstract state either by
5678 -- using an aspect or a pragma. If this is the case, build shadow
5679 -- entities for all abstract states of Pack.
5681 procedure Process_States
(States
: Elist_Id
);
5682 -- Generate shadow entities for all abstract states in list States
5684 -----------------------------
5685 -- Find_And_Process_States --
5686 -----------------------------
5688 procedure Find_And_Process_States
is
5689 procedure Process_State
(State
: Node_Id
);
5690 -- Generate shadow entities for a single abstract state or
5691 -- multiple states expressed as an aggregate.
5697 procedure Process_State
(State
: Node_Id
) is
5698 Loc
: constant Source_Ptr
:= Sloc
(State
);
5705 -- Multiple abstract states appear as an aggregate
5707 if Nkind
(State
) = N_Aggregate
then
5708 Elmt
:= First
(Expressions
(State
));
5709 while Present
(Elmt
) loop
5710 Process_State
(Elmt
);
5716 -- A null state has no abstract view
5718 elsif Nkind
(State
) = N_Null
then
5721 -- State declaration with various options appears as an
5722 -- extension aggregate.
5724 elsif Nkind
(State
) = N_Extension_Aggregate
then
5725 Decl
:= Ancestor_Part
(State
);
5727 -- Simple state declaration
5729 elsif Nkind
(State
) = N_Identifier
then
5732 -- Possibly an illegal state declaration
5738 -- Abstract states are elaborated when the related pragma is
5739 -- elaborated. Since the withed package is not analyzed yet,
5740 -- the entities of the abstract states are not available. To
5741 -- overcome this complication, create the entities now and
5742 -- store them in their respective declarations. The entities
5743 -- are later used by routine Create_Abstract_State to declare
5744 -- and enter the states into visibility.
5746 if No
(Entity
(Decl
)) then
5747 Id
:= Make_Defining_Identifier
(Loc
, Chars
(Decl
));
5749 Set_Entity
(Decl
, Id
);
5750 Set_Parent
(Id
, State
);
5751 Decorate_State
(Id
, Scop
);
5753 -- Otherwise the package was previously withed
5756 Id
:= Entity
(Decl
);
5759 Build_Shadow_Entity
(Id
, Scop
, Dummy
);
5764 Pack_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Pack
);
5768 -- Start of processing for Find_And_Process_States
5771 -- Find aspect Abstract_State
5773 Asp
:= First
(Aspect_Specifications
(Pack_Decl
));
5774 while Present
(Asp
) loop
5775 if Chars
(Identifier
(Asp
)) = Name_Abstract_State
then
5776 Process_State
(Expression
(Asp
));
5784 -- Find pragma Abstract_State by inspecting the declarations
5786 Decl
:= First
(Decls
);
5787 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
5788 if Pragma_Name
(Decl
) = Name_Abstract_State
then
5791 (First
(Pragma_Argument_Associations
(Decl
))));
5798 end Find_And_Process_States
;
5800 --------------------
5801 -- Process_States --
5802 --------------------
5804 procedure Process_States
(States
: Elist_Id
) is
5809 Elmt
:= First_Elmt
(States
);
5810 while Present
(Elmt
) loop
5811 Build_Shadow_Entity
(Node
(Elmt
), Scop
, Dummy
);
5819 Is_Tagged
: Boolean;
5825 -- Start of processing for Process_Declarations_And_States
5828 -- Build abstract views for all states defined in the package
5830 if Create_Abstract_Views
then
5832 -- When a package has been analyzed, all states are stored in list
5833 -- Abstract_States. Generate the shadow entities directly.
5836 if Present
(Abstract_States
(Pack
)) then
5837 Process_States
(Abstract_States
(Pack
));
5840 -- The package may declare abstract states by using an aspect or a
5841 -- pragma. Attempt to locate one of these construct and if found,
5842 -- build the shadow entities.
5845 Find_And_Process_States
;
5849 -- Inspect the declarative list, looking for nested packages, types
5850 -- and variable declarations.
5852 Decl
:= First
(Decls
);
5853 while Present
(Decl
) loop
5857 if Nkind
(Decl
) = N_Package_Declaration
then
5858 Def_Id
:= Defining_Entity
(Decl
);
5860 -- Perform minor decoration when the withed package has not
5863 if not Is_Analyzed
then
5864 Decorate_Package
(Def_Id
, Scop
);
5867 -- Create a shadow entity that offers a limited view of all
5868 -- visible types declared within.
5870 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5872 Process_Declarations_And_States
5874 Decls
=> Visible_Declarations
(Specification
(Decl
)),
5876 Create_Abstract_Views
=> Create_Abstract_Views
);
5880 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
5881 N_Incomplete_Type_Declaration
,
5882 N_Private_Extension_Declaration
,
5883 N_Private_Type_Declaration
,
5884 N_Protected_Type_Declaration
,
5885 N_Task_Type_Declaration
)
5887 Def_Id
:= Defining_Entity
(Decl
);
5889 -- Determine whether the type is tagged. Note that packages
5890 -- included via a limited with clause are not always analyzed,
5891 -- hence the tree lookup rather than the use of attribute
5894 if Nkind
(Decl
) = N_Full_Type_Declaration
then
5895 Def
:= Type_Definition
(Decl
);
5898 (Nkind
(Def
) = N_Record_Definition
5899 and then Tagged_Present
(Def
))
5901 (Nkind
(Def
) = N_Derived_Type_Definition
5902 and then Present
(Record_Extension_Part
(Def
)));
5904 elsif Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
5905 N_Private_Type_Declaration
)
5907 Is_Tagged
:= Tagged_Present
(Decl
);
5909 elsif Nkind
(Decl
) = N_Private_Extension_Declaration
then
5916 -- Perform minor decoration when the withed package has not
5919 if not Is_Analyzed
then
5920 Decorate_Type
(Def_Id
, Scop
, Is_Tagged
, True);
5923 -- Create a shadow entity that hides the type and offers an
5924 -- incomplete view of the said type.
5926 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
, Is_Tagged
);
5930 elsif Create_Abstract_Views
5931 and then Nkind
(Decl
) = N_Object_Declaration
5932 and then not Constant_Present
(Decl
)
5934 Def_Id
:= Defining_Entity
(Decl
);
5936 -- Perform minor decoration when the withed package has not
5939 if not Is_Analyzed
then
5940 Decorate_Variable
(Def_Id
, Scop
);
5943 -- Create a shadow entity that hides the variable and offers an
5944 -- abstract view of the said variable.
5946 Build_Shadow_Entity
(Def_Id
, Scop
, Shadow
);
5951 end Process_Declarations_And_States
;
5955 Nam
: constant Node_Id
:= Name
(N
);
5956 Pack
: constant Entity_Id
:= Cunit_Entity
(Unum
);
5958 Last_Public_Shadow
: Entity_Id
:= Empty
;
5959 Private_Shadow
: Entity_Id
;
5962 -- Start of processing for Build_Limited_Views
5965 pragma Assert
(Limited_Present
(N
));
5967 -- A library_item mentioned in a limited_with_clause is a package
5968 -- declaration, not a subprogram declaration, generic declaration,
5969 -- generic instantiation, or package renaming declaration.
5971 case Nkind
(Unit
(Library_Unit
(N
))) is
5972 when N_Package_Declaration
=>
5975 when N_Subprogram_Declaration
=>
5976 Error_Msg_N
("subprograms not allowed in limited with_clauses", N
);
5979 when N_Generic_Package_Declaration |
5980 N_Generic_Subprogram_Declaration
=>
5981 Error_Msg_N
("generics not allowed in limited with_clauses", N
);
5984 when N_Generic_Instantiation
=>
5986 ("generic instantiations not allowed in limited with_clauses",
5990 when N_Generic_Renaming_Declaration
=>
5992 ("generic renamings not allowed in limited with_clauses", N
);
5995 when N_Subprogram_Renaming_Declaration
=>
5997 ("renamed subprograms not allowed in limited with_clauses", N
);
6000 when N_Package_Renaming_Declaration
=>
6002 ("renamed packages not allowed in limited with_clauses", N
);
6006 raise Program_Error
;
6009 -- The withed unit may not be analyzed, but the with calause itself
6010 -- must be minimally decorated. This ensures that the checks on unused
6011 -- with clauses also process limieted withs.
6013 Set_Ekind
(Pack
, E_Package
);
6014 Set_Etype
(Pack
, Standard_Void_Type
);
6016 if Is_Entity_Name
(Nam
) then
6017 Set_Entity
(Nam
, Pack
);
6019 elsif Nkind
(Nam
) = N_Selected_Component
then
6020 Set_Entity
(Selector_Name
(Nam
), Pack
);
6023 -- Check if the chain is already built
6025 Spec
:= Specification
(Unit
(Library_Unit
(N
)));
6027 if Limited_View_Installed
(Spec
) then
6031 -- Create the shadow package wich hides the withed unit and provides
6032 -- incomplete view of all types and packages declared within.
6034 Shadow_Pack
:= Make_Temporary
(Sloc
(N
), 'Z');
6035 Set_Ekind
(Shadow_Pack
, E_Package
);
6036 Set_Is_Internal
(Shadow_Pack
);
6037 Set_Limited_View
(Pack
, Shadow_Pack
);
6039 -- Inspect the abstract states and visible declarations of the withed
6040 -- unit and create shadow entities that hide existing packages, states,
6041 -- variables and types.
6043 Process_Declarations_And_States
6045 Decls
=> Visible_Declarations
(Spec
),
6047 Create_Abstract_Views
=> True);
6049 Last_Public_Shadow
:= Last_Shadow
;
6051 -- Ada 2005 (AI-262): Build the limited view of the private declarations
6052 -- to accomodate limited private with clauses.
6054 Process_Declarations_And_States
6056 Decls
=> Private_Declarations
(Spec
),
6058 Create_Abstract_Views
=> False);
6060 if Present
(Last_Public_Shadow
) then
6061 Private_Shadow
:= Next_Entity
(Last_Public_Shadow
);
6063 Private_Shadow
:= First_Entity
(Shadow_Pack
);
6066 Set_First_Private_Entity
(Shadow_Pack
, Private_Shadow
);
6067 Set_Limited_View_Installed
(Spec
);
6068 end Build_Limited_Views
;
6070 ----------------------------
6071 -- Check_No_Elab_Code_All --
6072 ----------------------------
6074 procedure Check_No_Elab_Code_All
(N
: Node_Id
) is
6076 if Present
(No_Elab_Code_All_Pragma
)
6077 and then In_Extended_Main_Source_Unit
(N
)
6078 and then Present
(Context_Items
(N
))
6081 CL
: constant List_Id
:= Context_Items
(N
);
6086 while Present
(CI
) loop
6087 if Nkind
(CI
) = N_With_Clause
6089 No_Elab_Code_All
(Get_Source_Unit
(Library_Unit
(CI
)))
6091 Error_Msg_Sloc
:= Sloc
(No_Elab_Code_All_Pragma
);
6093 ("violation of No_Elaboration_Code_All#", CI
);
6095 ("\unit& does not have No_Elaboration_Code_All",
6096 CI
, Entity
(Name
(CI
)));
6103 end Check_No_Elab_Code_All
;
6105 -------------------------------
6106 -- Check_Body_Needed_For_SAL --
6107 -------------------------------
6109 procedure Check_Body_Needed_For_SAL
(Unit_Name
: Entity_Id
) is
6111 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean;
6112 -- Determine whether use of entity E might require the presence of its
6113 -- body. For a package this requires a recursive traversal of all nested
6116 ---------------------------
6117 -- Entity_Needed_For_SAL --
6118 ---------------------------
6120 function Entity_Needs_Body
(E
: Entity_Id
) return Boolean is
6124 if Is_Subprogram
(E
) and then Has_Pragma_Inline
(E
) then
6127 elsif Ekind_In
(E
, E_Generic_Function
, E_Generic_Procedure
) then
6130 elsif Ekind
(E
) = E_Generic_Package
6132 Nkind
(Unit_Declaration_Node
(E
)) = N_Generic_Package_Declaration
6133 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6137 elsif Ekind
(E
) = E_Package
6138 and then Nkind
(Unit_Declaration_Node
(E
)) = N_Package_Declaration
6139 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(E
)))
6141 Ent
:= First_Entity
(E
);
6142 while Present
(Ent
) loop
6143 if Entity_Needs_Body
(Ent
) then
6155 end Entity_Needs_Body
;
6157 -- Start of processing for Check_Body_Needed_For_SAL
6160 if Ekind
(Unit_Name
) = E_Generic_Package
6161 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6162 N_Generic_Package_Declaration
6164 Present
(Corresponding_Body
(Unit_Declaration_Node
(Unit_Name
)))
6166 Set_Body_Needed_For_SAL
(Unit_Name
);
6168 elsif Ekind_In
(Unit_Name
, E_Generic_Procedure
, E_Generic_Function
) then
6169 Set_Body_Needed_For_SAL
(Unit_Name
);
6171 elsif Is_Subprogram
(Unit_Name
)
6172 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) =
6173 N_Subprogram_Declaration
6174 and then Has_Pragma_Inline
(Unit_Name
)
6176 Set_Body_Needed_For_SAL
(Unit_Name
);
6178 elsif Ekind
(Unit_Name
) = E_Subprogram_Body
then
6179 Check_Body_Needed_For_SAL
6180 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6182 elsif Ekind
(Unit_Name
) = E_Package
6183 and then Entity_Needs_Body
(Unit_Name
)
6185 Set_Body_Needed_For_SAL
(Unit_Name
);
6187 elsif Ekind
(Unit_Name
) = E_Package_Body
6188 and then Nkind
(Unit_Declaration_Node
(Unit_Name
)) = N_Package_Body
6190 Check_Body_Needed_For_SAL
6191 (Corresponding_Spec
(Unit_Declaration_Node
(Unit_Name
)));
6193 end Check_Body_Needed_For_SAL
;
6195 --------------------
6196 -- Remove_Context --
6197 --------------------
6199 procedure Remove_Context
(N
: Node_Id
) is
6200 Lib_Unit
: constant Node_Id
:= Unit
(N
);
6203 -- If this is a child unit, first remove the parent units
6205 if Is_Child_Spec
(Lib_Unit
) then
6206 Remove_Parents
(Lib_Unit
);
6209 Remove_Context_Clauses
(N
);
6212 ----------------------------
6213 -- Remove_Context_Clauses --
6214 ----------------------------
6216 procedure Remove_Context_Clauses
(N
: Node_Id
) is
6218 Unit_Name
: Entity_Id
;
6221 -- Ada 2005 (AI-50217): We remove the context clauses in two phases:
6222 -- limited-views first and regular-views later (to maintain the
6225 -- First Phase: Remove limited_with context clauses
6227 Item
:= First
(Context_Items
(N
));
6228 while Present
(Item
) loop
6230 -- We are interested only in with clauses which got installed
6233 if Nkind
(Item
) = N_With_Clause
6234 and then Limited_Present
(Item
)
6235 and then Limited_View_Installed
(Item
)
6237 Remove_Limited_With_Clause
(Item
);
6243 -- Second Phase: Loop through context items and undo regular
6244 -- with_clauses and use_clauses.
6246 Item
:= First
(Context_Items
(N
));
6247 while Present
(Item
) loop
6249 -- We are interested only in with clauses which got installed on
6250 -- entry, as indicated by their Context_Installed flag set
6252 if Nkind
(Item
) = N_With_Clause
6253 and then Limited_Present
(Item
)
6254 and then Limited_View_Installed
(Item
)
6258 elsif Nkind
(Item
) = N_With_Clause
6259 and then Context_Installed
(Item
)
6261 -- Remove items from one with'ed unit
6263 Unit_Name
:= Entity
(Name
(Item
));
6264 Remove_Unit_From_Visibility
(Unit_Name
);
6265 Set_Context_Installed
(Item
, False);
6267 elsif Nkind
(Item
) = N_Use_Package_Clause
then
6268 End_Use_Package
(Item
);
6270 elsif Nkind
(Item
) = N_Use_Type_Clause
then
6271 End_Use_Type
(Item
);
6276 end Remove_Context_Clauses
;
6278 --------------------------------
6279 -- Remove_Limited_With_Clause --
6280 --------------------------------
6282 procedure Remove_Limited_With_Clause
(N
: Node_Id
) is
6283 P_Unit
: constant Entity_Id
:= Unit
(Library_Unit
(N
));
6286 Lim_Header
: Entity_Id
;
6287 Lim_Typ
: Entity_Id
;
6291 pragma Assert
(Limited_View_Installed
(N
));
6293 -- In case of limited with_clause on subprograms, generics, instances,
6294 -- or renamings, the corresponding error was previously posted and we
6295 -- have nothing to do here.
6297 if Nkind
(P_Unit
) /= N_Package_Declaration
then
6301 P
:= Defining_Unit_Name
(Specification
(P_Unit
));
6303 -- Handle child packages
6305 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
6306 P
:= Defining_Identifier
(P
);
6309 if Debug_Flag_I
then
6310 Write_Str
("remove limited view of ");
6311 Write_Name
(Chars
(P
));
6312 Write_Str
(" from visibility");
6316 -- Prepare the removal of the shadow entities from visibility. The first
6317 -- element of the limited view is a header (an E_Package entity) that is
6318 -- used to reference the first shadow entity in the private part of the
6321 Lim_Header
:= Limited_View
(P
);
6322 Lim_Typ
:= First_Entity
(Lim_Header
);
6324 -- Remove package and shadow entities from visibility if it has not
6327 if not Analyzed
(P_Unit
) then
6329 Set_Is_Immediately_Visible
(P
, False);
6331 while Present
(Lim_Typ
) loop
6333 Next_Entity
(Lim_Typ
);
6336 -- Otherwise this package has already appeared in the closure and its
6337 -- shadow entities must be replaced by its real entities. This code
6338 -- must be kept synchronized with the complementary code in Install
6339 -- Limited_Withed_Unit.
6342 -- Real entities that are type or subtype declarations were hidden
6343 -- from visibility at the point of installation of the limited-view.
6344 -- Now we recover the previous value of the hidden attribute.
6346 E
:= First_Entity
(P
);
6347 while Present
(E
) and then E
/= First_Private_Entity
(P
) loop
6349 Set_Is_Hidden
(E
, Was_Hidden
(E
));
6355 while Present
(Lim_Typ
)
6356 and then Lim_Typ
/= First_Private_Entity
(Lim_Header
)
6358 -- Nested packages and child units were not unchained
6360 if Ekind
(Lim_Typ
) /= E_Package
6361 and then not Is_Child_Unit
(Non_Limited_View
(Lim_Typ
))
6363 -- If the package has incomplete types, the limited view of the
6364 -- incomplete type is in fact never visible (AI05-129) but we
6365 -- have created a shadow entity E1 for it, that points to E2,
6366 -- a non-limited incomplete type. This in turn has a full view
6367 -- E3 that is the full declaration. There is a corresponding
6368 -- shadow entity E4. When reinstalling the non-limited view,
6369 -- E2 must become the current entity and E3 must be ignored.
6371 E
:= Non_Limited_View
(Lim_Typ
);
6373 if Present
(Current_Entity
(E
))
6374 and then Ekind
(Current_Entity
(E
)) = E_Incomplete_Type
6375 and then Full_View
(Current_Entity
(E
)) = E
6378 -- Lim_Typ is the limited view of a full type declaration
6379 -- that has a previous incomplete declaration, i.e. E3 from
6380 -- the previous description. Nothing to insert.
6385 pragma Assert
(not In_Chain
(E
));
6387 Prev
:= Current_Entity
(Lim_Typ
);
6389 if Prev
= Lim_Typ
then
6390 Set_Current_Entity
(E
);
6393 while Present
(Prev
)
6394 and then Homonym
(Prev
) /= Lim_Typ
6396 Prev
:= Homonym
(Prev
);
6399 if Present
(Prev
) then
6400 Set_Homonym
(Prev
, E
);
6404 -- Preserve structure of homonym chain
6406 Set_Homonym
(E
, Homonym
(Lim_Typ
));
6410 Next_Entity
(Lim_Typ
);
6414 -- Indicate that the limited view of the package is not installed
6416 Set_From_Limited_With
(P
, False);
6417 Set_Limited_View_Installed
(N
, False);
6418 end Remove_Limited_With_Clause
;
6420 --------------------
6421 -- Remove_Parents --
6422 --------------------
6424 procedure Remove_Parents
(Lib_Unit
: Node_Id
) is
6427 P_Spec
: Node_Id
:= Empty
;
6429 Vis
: constant Boolean :=
6430 Scope_Stack
.Table
(Scope_Stack
.Last
).Previous_Visibility
;
6433 if Is_Child_Spec
(Lib_Unit
) then
6434 P_Spec
:= Parent_Spec
(Lib_Unit
);
6436 elsif Nkind
(Lib_Unit
) = N_Package_Body
6437 and then Nkind
(Original_Node
(Lib_Unit
)) = N_Package_Instantiation
6439 P_Spec
:= Parent_Spec
(Original_Node
(Lib_Unit
));
6442 if Present
(P_Spec
) then
6444 P_Name
:= Get_Parent_Entity
(P
);
6445 Remove_Context_Clauses
(P_Spec
);
6446 End_Package_Scope
(P_Name
);
6447 Set_Is_Immediately_Visible
(P_Name
, Vis
);
6449 -- Remove from visibility the siblings as well, which are directly
6450 -- visible while the parent is in scope.
6452 E
:= First_Entity
(P_Name
);
6453 while Present
(E
) loop
6454 if Is_Child_Unit
(E
) then
6455 Set_Is_Immediately_Visible
(E
, False);
6461 Set_In_Package_Body
(P_Name
, False);
6463 -- This is the recursive call to remove the context of any higher
6464 -- level parent. This recursion ensures that all parents are removed
6465 -- in the reverse order of their installation.
6471 ---------------------------------
6472 -- Remove_Private_With_Clauses --
6473 ---------------------------------
6475 procedure Remove_Private_With_Clauses
(Comp_Unit
: Node_Id
) is
6478 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean;
6479 -- Check whether a given unit appears in a regular with_clause. Used to
6480 -- determine whether a private_with_clause, implicit or explicit, should
6483 ----------------------------
6484 -- In_Regular_With_Clause --
6485 ----------------------------
6487 function In_Regular_With_Clause
(E
: Entity_Id
) return Boolean
6492 Item
:= First
(Context_Items
(Comp_Unit
));
6493 while Present
(Item
) loop
6494 if Nkind
(Item
) = N_With_Clause
6495 and then Entity
(Name
(Item
)) = E
6496 and then not Private_Present
(Item
)
6504 end In_Regular_With_Clause
;
6506 -- Start of processing for Remove_Private_With_Clauses
6509 Item
:= First
(Context_Items
(Comp_Unit
));
6510 while Present
(Item
) loop
6511 if Nkind
(Item
) = N_With_Clause
and then Private_Present
(Item
) then
6513 -- If private_with_clause is redundant, remove it from context,
6514 -- as a small optimization to subsequent handling of private_with
6515 -- clauses in other nested packages.
6517 if In_Regular_With_Clause
(Entity
(Name
(Item
))) then
6519 Nxt
: constant Node_Id
:= Next
(Item
);
6525 elsif Limited_Present
(Item
) then
6526 if not Limited_View_Installed
(Item
) then
6527 Remove_Limited_With_Clause
(Item
);
6533 Remove_Unit_From_Visibility
(Entity
(Name
(Item
)));
6534 Set_Context_Installed
(Item
, False);
6542 end Remove_Private_With_Clauses
;
6544 ---------------------------------
6545 -- Remove_Unit_From_Visibility --
6546 ---------------------------------
6548 procedure Remove_Unit_From_Visibility
(Unit_Name
: Entity_Id
) is
6550 if Debug_Flag_I
then
6551 Write_Str
("remove unit ");
6552 Write_Name
(Chars
(Unit_Name
));
6553 Write_Str
(" from visibility");
6557 Set_Is_Visible_Lib_Unit
(Unit_Name
, False);
6558 Set_Is_Potentially_Use_Visible
(Unit_Name
, False);
6559 Set_Is_Immediately_Visible
(Unit_Name
, False);
6561 -- If the unit is a wrapper package, the subprogram instance is
6562 -- what must be removed from visibility.
6563 -- Should we use Related_Instance instead???
6565 if Is_Wrapper_Package
(Unit_Name
) then
6566 Set_Is_Immediately_Visible
(Current_Entity
(Unit_Name
), False);
6568 end Remove_Unit_From_Visibility
;
6583 procedure Unchain
(E
: Entity_Id
) is
6587 Prev
:= Current_Entity
(E
);
6593 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6596 while Present
(Prev
) and then Homonym
(Prev
) /= E
loop
6597 Prev
:= Homonym
(Prev
);
6600 if Present
(Prev
) then
6601 Set_Homonym
(Prev
, Homonym
(E
));
6605 if Debug_Flag_I
then
6606 Write_Str
(" (homonym) unchain ");
6607 Write_Name
(Chars
(E
));