1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 -- This package contains the routines to process package specifications and
27 -- bodies. The most important semantic aspects of package processing are the
28 -- handling of private and full declarations, and the construction of dispatch
29 -- tables for tagged types.
31 with Atree
; use Atree
;
32 with Debug
; use Debug
;
33 with Einfo
; use Einfo
;
34 with Elists
; use Elists
;
35 with Errout
; use Errout
;
36 with Exp_Disp
; use Exp_Disp
;
37 with Exp_Dist
; use Exp_Dist
;
38 with Exp_Dbug
; use Exp_Dbug
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Nmake
; use Nmake
;
43 with Nlists
; use Nlists
;
45 with Output
; use Output
;
47 with Sem_Aux
; use Sem_Aux
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Ch10
; use Sem_Ch10
;
53 with Sem_Ch12
; use Sem_Ch12
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Util
; use Sem_Util
;
57 with Sem_Warn
; use Sem_Warn
;
58 with Snames
; use Snames
;
59 with Stand
; use Stand
;
60 with Sinfo
; use Sinfo
;
61 with Sinput
; use Sinput
;
63 with Uintp
; use Uintp
;
65 package body Sem_Ch7
is
67 -----------------------------------
68 -- Handling private declarations --
69 -----------------------------------
71 -- The principle that each entity has a single defining occurrence clashes
72 -- with the presence of two separate definitions for private types: the
73 -- first is the private type declaration, and the second is the full type
74 -- declaration. It is important that all references to the type point to
75 -- the same defining occurrence, namely the first one. To enforce the two
76 -- separate views of the entity, the corresponding information is swapped
77 -- between the two declarations. Outside of the package, the defining
78 -- occurrence only contains the private declaration information, while in
79 -- the private part and the body of the package the defining occurrence
80 -- contains the full declaration. To simplify the swap, the defining
81 -- occurrence that currently holds the private declaration points to the
82 -- full declaration. During semantic processing the defining occurrence
83 -- also points to a list of private dependents, that is to say access types
84 -- or composite types whose designated types or component types are
85 -- subtypes or derived types of the private type in question. After the
86 -- full declaration has been seen, the private dependents are updated to
87 -- indicate that they have full definitions.
89 -----------------------
90 -- Local Subprograms --
91 -----------------------
93 procedure Analyze_Package_Body_Helper
(N
: Node_Id
);
94 -- Does all the real work of Analyze_Package_Body
96 procedure Check_Anonymous_Access_Types
99 -- If the spec of a package has a limited_with_clause, it may declare
100 -- anonymous access types whose designated type is a limited view, such an
101 -- anonymous access return type for a function. This access type cannot be
102 -- elaborated in the spec itself, but it may need an itype reference if it
103 -- is used within a nested scope. In that case the itype reference is
104 -- created at the beginning of the corresponding package body and inserted
105 -- before other body declarations.
107 procedure Install_Package_Entity
(Id
: Entity_Id
);
108 -- Supporting procedure for Install_{Visible,Private}_Declarations. Places
109 -- one entity on its visibility chain, and recurses on the visible part if
110 -- the entity is an inner package.
112 function Is_Private_Base_Type
(E
: Entity_Id
) return Boolean;
113 -- True for a private type that is not a subtype
115 function Is_Visible_Dependent
(Dep
: Entity_Id
) return Boolean;
116 -- If the private dependent is a private type whose full view is derived
117 -- from the parent type, its full properties are revealed only if we are in
118 -- the immediate scope of the private dependent. Should this predicate be
119 -- tightened further???
121 procedure Declare_Inherited_Private_Subprograms
(Id
: Entity_Id
);
122 -- Called upon entering the private part of a public child package and the
123 -- body of a nested package, to potentially declare certain inherited
124 -- subprograms that were inherited by types in the visible part, but whose
125 -- declaration was deferred because the parent operation was private and
126 -- not visible at that point. These subprograms are located by traversing
127 -- the visible part declarations looking for non-private type extensions
128 -- and then examining each of the primitive operations of such types to
129 -- find those that were inherited but declared with a special internal
130 -- name. Each such operation is now declared as an operation with a normal
131 -- name (using the name of the parent operation) and replaces the previous
132 -- implicit operation in the primitive operations list of the type. If the
133 -- inherited private operation has been overridden, then it's replaced by
134 -- the overriding operation.
136 --------------------------
137 -- Analyze_Package_Body --
138 --------------------------
140 procedure Analyze_Package_Body
(N
: Node_Id
) is
141 Loc
: constant Source_Ptr
:= Sloc
(N
);
145 Write_Str
("==> package body ");
146 Write_Name
(Chars
(Defining_Entity
(N
)));
147 Write_Str
(" from ");
148 Write_Location
(Loc
);
153 -- The real work is split out into the helper, so it can do "return;"
154 -- without skipping the debug output.
156 Analyze_Package_Body_Helper
(N
);
160 Write_Str
("<== package body ");
161 Write_Name
(Chars
(Defining_Entity
(N
)));
162 Write_Str
(" from ");
163 Write_Location
(Loc
);
166 end Analyze_Package_Body
;
168 ---------------------------------
169 -- Analyze_Package_Body_Helper --
170 ---------------------------------
172 procedure Analyze_Package_Body_Helper
(N
: Node_Id
) is
176 Last_Spec_Entity
: Entity_Id
;
180 procedure Install_Composite_Operations
(P
: Entity_Id
);
181 -- Composite types declared in the current scope may depend on types
182 -- that were private at the point of declaration, and whose full view
183 -- is now in scope. Indicate that the corresponding operations on the
184 -- composite type are available.
186 ----------------------------------
187 -- Install_Composite_Operations --
188 ----------------------------------
190 procedure Install_Composite_Operations
(P
: Entity_Id
) is
194 Id
:= First_Entity
(P
);
195 while Present
(Id
) loop
197 and then (Is_Limited_Composite
(Id
)
198 or else Is_Private_Composite
(Id
))
199 and then No
(Private_Component
(Id
))
201 Set_Is_Limited_Composite
(Id
, False);
202 Set_Is_Private_Composite
(Id
, False);
207 end Install_Composite_Operations
;
209 -- Start of processing for Analyze_Package_Body_Helper
212 -- Find corresponding package specification, and establish the current
213 -- scope. The visible defining entity for the package is the defining
214 -- occurrence in the spec. On exit from the package body, all body
215 -- declarations are attached to the defining entity for the body, but
216 -- the later is never used for name resolution. In this fashion there
217 -- is only one visible entity that denotes the package.
219 -- Set Body_Id. Note that this Will be reset to point to the generic
220 -- copy later on in the generic case.
222 Body_Id
:= Defining_Entity
(N
);
224 if Present
(Corresponding_Spec
(N
)) then
226 -- Body is body of package instantiation. Corresponding spec has
229 Spec_Id
:= Corresponding_Spec
(N
);
230 Pack_Decl
:= Unit_Declaration_Node
(Spec_Id
);
233 Spec_Id
:= Current_Entity_In_Scope
(Defining_Entity
(N
));
236 and then Is_Package_Or_Generic_Package
(Spec_Id
)
238 Pack_Decl
:= Unit_Declaration_Node
(Spec_Id
);
240 if Nkind
(Pack_Decl
) = N_Package_Renaming_Declaration
then
241 Error_Msg_N
("cannot supply body for package renaming", N
);
244 elsif Present
(Corresponding_Body
(Pack_Decl
)) then
245 Error_Msg_N
("redefinition of package body", N
);
250 Error_Msg_N
("missing specification for package body", N
);
254 if Is_Package_Or_Generic_Package
(Spec_Id
)
256 (Scope
(Spec_Id
) = Standard_Standard
257 or else Is_Child_Unit
(Spec_Id
))
258 and then not Unit_Requires_Body
(Spec_Id
)
260 if Ada_Version
= Ada_83
then
262 ("optional package body (not allowed in Ada 95)?", N
);
264 Error_Msg_N
("spec of this package does not allow a body", N
);
269 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
270 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
272 if Is_Child_Unit
(Spec_Id
) then
273 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
275 ("body of child unit& cannot be an inner package", N
, Spec_Id
);
278 Set_Is_Child_Unit
(Body_Id
);
281 -- Generic package case
283 if Ekind
(Spec_Id
) = E_Generic_Package
then
285 -- Disable expansion and perform semantic analysis on copy. The
286 -- unannotated body will be used in all instantiations.
288 Body_Id
:= Defining_Entity
(N
);
289 Set_Ekind
(Body_Id
, E_Package_Body
);
290 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
291 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
292 Set_Body_Entity
(Spec_Id
, Body_Id
);
293 Set_Spec_Entity
(Body_Id
, Spec_Id
);
295 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
298 -- Update Body_Id to point to the copied node for the remainder of
301 Body_Id
:= Defining_Entity
(N
);
305 -- The Body_Id is that of the copied node in the generic case, the
306 -- current node otherwise. Note that N was rewritten above, so we must
307 -- be sure to get the latest Body_Id value.
309 Set_Ekind
(Body_Id
, E_Package_Body
);
310 Set_Body_Entity
(Spec_Id
, Body_Id
);
311 Set_Spec_Entity
(Body_Id
, Spec_Id
);
313 -- Defining name for the package body is not a visible entity: Only the
314 -- defining name for the declaration is visible.
316 Set_Etype
(Body_Id
, Standard_Void_Type
);
317 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
318 Set_Corresponding_Spec
(N
, Spec_Id
);
319 Set_Corresponding_Body
(Pack_Decl
, Body_Id
);
321 -- The body entity is not used for semantics or code generation, but
322 -- it is attached to the entity list of the enclosing scope to simplify
323 -- the listing of back-annotations for the types it main contain.
325 if Scope
(Spec_Id
) /= Standard_Standard
then
326 Append_Entity
(Body_Id
, Scope
(Spec_Id
));
329 -- Indicate that we are currently compiling the body of the package
331 Set_In_Package_Body
(Spec_Id
);
332 Set_Has_Completion
(Spec_Id
);
333 Last_Spec_Entity
:= Last_Entity
(Spec_Id
);
335 Push_Scope
(Spec_Id
);
337 Set_Categorization_From_Pragmas
(N
);
339 Install_Visible_Declarations
(Spec_Id
);
340 Install_Private_Declarations
(Spec_Id
);
341 Install_Private_With_Clauses
(Spec_Id
);
342 Install_Composite_Operations
(Spec_Id
);
344 Check_Anonymous_Access_Types
(Spec_Id
, N
);
346 if Ekind
(Spec_Id
) = E_Generic_Package
then
347 Set_Use
(Generic_Formal_Declarations
(Pack_Decl
));
350 Set_Use
(Visible_Declarations
(Specification
(Pack_Decl
)));
351 Set_Use
(Private_Declarations
(Specification
(Pack_Decl
)));
353 -- This is a nested package, so it may be necessary to declare certain
354 -- inherited subprograms that are not yet visible because the parent
355 -- type's subprograms are now visible.
357 if Ekind
(Scope
(Spec_Id
)) = E_Package
358 and then Scope
(Spec_Id
) /= Standard_Standard
360 Declare_Inherited_Private_Subprograms
(Spec_Id
);
363 if Present
(Declarations
(N
)) then
364 Analyze_Declarations
(Declarations
(N
));
365 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
368 -- Analyze_Declarations has caused freezing of all types. Now generate
369 -- bodies for RACW primitives and stream attributes, if any.
371 if Ekind
(Spec_Id
) = E_Package
and then Has_RACW
(Spec_Id
) then
373 -- Attach subprogram bodies to support RACWs declared in spec
375 Append_RACW_Bodies
(Declarations
(N
), Spec_Id
);
376 Analyze_List
(Declarations
(N
));
379 HSS
:= Handled_Statement_Sequence
(N
);
381 if Present
(HSS
) then
382 Process_End_Label
(HSS
, 't', Spec_Id
);
385 -- Check that elaboration code in a preelaborable package body is
386 -- empty other than null statements and labels (RM 10.2.1(6)).
388 Validate_Null_Statement_Sequence
(N
);
391 Validate_Categorization_Dependency
(N
, Spec_Id
);
392 Check_Completion
(Body_Id
);
394 -- Generate start of body reference. Note that we do this fairly late,
395 -- because the call will use In_Extended_Main_Source_Unit as a check,
396 -- and we want to make sure that Corresponding_Stub links are set
398 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
400 -- For a generic package, collect global references and mark them on
401 -- the original body so that they are not resolved again at the point
404 if Ekind
(Spec_Id
) /= E_Package
then
405 Save_Global_References
(Original_Node
(N
));
409 -- The entities of the package body have so far been chained onto the
410 -- declaration chain for the spec. That's been fine while we were in the
411 -- body, since we wanted them to be visible, but now that we are leaving
412 -- the package body, they are no longer visible, so we remove them from
413 -- the entity chain of the package spec entity, and copy them to the
414 -- entity chain of the package body entity, where they will never again
417 if Present
(Last_Spec_Entity
) then
418 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Spec_Entity
));
419 Set_Next_Entity
(Last_Spec_Entity
, Empty
);
420 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
421 Set_Last_Entity
(Spec_Id
, Last_Spec_Entity
);
424 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
425 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
426 Set_First_Entity
(Spec_Id
, Empty
);
427 Set_Last_Entity
(Spec_Id
, Empty
);
430 End_Package_Scope
(Spec_Id
);
432 -- All entities declared in body are not visible
438 E
:= First_Entity
(Body_Id
);
439 while Present
(E
) loop
440 Set_Is_Immediately_Visible
(E
, False);
441 Set_Is_Potentially_Use_Visible
(E
, False);
444 -- Child units may appear on the entity list (e.g. if they appear
445 -- in the context of a subunit) but they are not body entities.
447 if not Is_Child_Unit
(E
) then
448 Set_Is_Package_Body_Entity
(E
);
455 Check_References
(Body_Id
);
457 -- For a generic unit, check that the formal parameters are referenced,
458 -- and that local variables are used, as for regular packages.
460 if Ekind
(Spec_Id
) = E_Generic_Package
then
461 Check_References
(Spec_Id
);
464 -- The processing so far has made all entities of the package body
465 -- public (i.e. externally visible to the linker). This is in general
466 -- necessary, since inlined or generic bodies, for which code is
467 -- generated in other units, may need to see these entities. The
468 -- following loop runs backwards from the end of the entities of the
469 -- package body making these entities invisible until we reach a
470 -- referencer, i.e. a declaration that could reference a previous
471 -- declaration, a generic body or an inlined body, or a stub (which may
472 -- contain either of these). This is of course an approximation, but it
473 -- is conservative and definitely correct.
475 -- We only do this at the outer (library) level non-generic packages.
476 -- The reason is simply to cut down on the number of external symbols
477 -- generated, so this is simply an optimization of the efficiency
478 -- of the compilation process. It has no other effect.
480 if (Scope
(Spec_Id
) = Standard_Standard
or else Is_Child_Unit
(Spec_Id
))
481 and then not Is_Generic_Unit
(Spec_Id
)
482 and then Present
(Declarations
(N
))
484 Make_Non_Public_Where_Possible
: declare
486 function Has_Referencer
490 -- Traverse the given list of declarations in reverse order.
491 -- Return True as soon as a referencer is reached. Return False if
492 -- none is found. The Outer parameter is True for the outer level
493 -- call, and False for inner level calls for nested packages. If
494 -- Outer is True, then any entities up to the point of hitting a
495 -- referencer get their Is_Public flag cleared, so that the
496 -- entities will be treated as static entities in the C sense, and
497 -- need not have fully qualified names. For inner levels, we need
498 -- all names to be fully qualified to deal with the same name
499 -- appearing in parallel packages (right now this is tied to their
506 function Has_Referencer
522 while Present
(D
) loop
525 if K
in N_Body_Stub
then
528 elsif K
= N_Subprogram_Body
then
529 if Acts_As_Spec
(D
) then
530 E
:= Defining_Entity
(D
);
532 -- An inlined body acts as a referencer. Note also
533 -- that we never reset Is_Public for an inlined
534 -- subprogram. Gigi requires Is_Public to be set.
536 -- Note that we test Has_Pragma_Inline here rather
537 -- than Is_Inlined. We are compiling this for a
538 -- client, and it is the client who will decide if
539 -- actual inlining should occur, so we need to assume
540 -- that the procedure could be inlined for the purpose
541 -- of accessing global entities.
543 if Has_Pragma_Inline
(E
) then
546 Set_Is_Public
(E
, False);
550 E
:= Corresponding_Spec
(D
);
553 and then (Is_Generic_Unit
(E
)
554 or else Has_Pragma_Inline
(E
)
555 or else Is_Inlined
(E
))
561 -- Processing for package bodies
563 elsif K
= N_Package_Body
564 and then Present
(Corresponding_Spec
(D
))
566 E
:= Corresponding_Spec
(D
);
568 -- Generic package body is a referencer. It would seem
569 -- that we only have to consider generics that can be
570 -- exported, i.e. where the corresponding spec is the
571 -- spec of the current package, but because of nested
572 -- instantiations, a fully private generic body may
573 -- export other private body entities.
575 if Is_Generic_Unit
(E
) then
578 -- For non-generic package body, recurse into body unless
579 -- this is an instance, we ignore instances since they
580 -- cannot have references that affect outer entities.
582 elsif not Is_Generic_Instance
(E
) then
584 (Declarations
(D
), Outer
=> False)
590 -- Processing for package specs, recurse into declarations.
591 -- Again we skip this for the case of generic instances.
593 elsif K
= N_Package_Declaration
then
594 S
:= Specification
(D
);
596 if not Is_Generic_Unit
(Defining_Entity
(S
)) then
598 (Private_Declarations
(S
), Outer
=> False)
602 (Visible_Declarations
(S
), Outer
=> False)
608 -- Objects and exceptions need not be public if we have not
609 -- encountered a referencer so far. We only reset the flag
610 -- for outer level entities that are not imported/exported,
611 -- and which have no interface name.
613 elsif Nkind_In
(K
, N_Object_Declaration
,
614 N_Exception_Declaration
,
615 N_Subprogram_Declaration
)
617 E
:= Defining_Entity
(D
);
620 and then not Is_Imported
(E
)
621 and then not Is_Exported
(E
)
622 and then No
(Interface_Name
(E
))
624 Set_Is_Public
(E
, False);
634 -- Start of processing for Make_Non_Public_Where_Possible
639 pragma Warnings
(Off
, Discard
);
642 Discard
:= Has_Referencer
(Declarations
(N
), Outer
=> True);
644 end Make_Non_Public_Where_Possible
;
647 -- If expander is not active, then here is where we turn off the
648 -- In_Package_Body flag, otherwise it is turned off at the end of the
649 -- corresponding expansion routine. If this is an instance body, we need
650 -- to qualify names of local entities, because the body may have been
651 -- compiled as a preliminary to another instantiation.
653 if not Expander_Active
then
654 Set_In_Package_Body
(Spec_Id
, False);
656 if Is_Generic_Instance
(Spec_Id
)
657 and then Operating_Mode
= Generate_Code
659 Qualify_Entity_Names
(N
);
662 end Analyze_Package_Body_Helper
;
664 ---------------------------------
665 -- Analyze_Package_Declaration --
666 ---------------------------------
668 procedure Analyze_Package_Declaration
(N
: Node_Id
) is
669 Id
: constant Node_Id
:= Defining_Entity
(N
);
672 -- True when in the context of a declared pure library unit
674 Body_Required
: Boolean;
675 -- True when this package declaration requires a corresponding body
678 -- True when this package declaration is not a nested declaration
681 -- Ada 2005 (AI-217): Check if the package has been erroneously named
682 -- in a limited-with clause of its own context. In this case the error
683 -- has been previously notified by Analyze_Context.
685 -- limited with Pkg; -- ERROR
686 -- package Pkg is ...
688 if From_With_Type
(Id
) then
693 Write_Str
("==> package spec ");
694 Write_Name
(Chars
(Id
));
695 Write_Str
(" from ");
696 Write_Location
(Sloc
(N
));
701 Generate_Definition
(Id
);
703 Set_Ekind
(Id
, E_Package
);
704 Set_Etype
(Id
, Standard_Void_Type
);
708 PF
:= Is_Pure
(Enclosing_Lib_Unit_Entity
);
709 Set_Is_Pure
(Id
, PF
);
711 Set_Categorization_From_Pragmas
(N
);
713 Analyze
(Specification
(N
));
714 Validate_Categorization_Dependency
(N
, Id
);
716 Body_Required
:= Unit_Requires_Body
(Id
);
718 -- When this spec does not require an explicit body, we know that there
719 -- are no entities requiring completion in the language sense; we call
720 -- Check_Completion here only to ensure that any nested package
721 -- declaration that requires an implicit body gets one. (In the case
722 -- where a body is required, Check_Completion is called at the end of
723 -- the body's declarative part.)
725 if not Body_Required
then
729 Comp_Unit
:= Nkind
(Parent
(N
)) = N_Compilation_Unit
;
732 -- Set Body_Required indication on the compilation unit node, and
733 -- determine whether elaboration warnings may be meaningful on it.
735 Set_Body_Required
(Parent
(N
), Body_Required
);
737 if not Body_Required
then
738 Set_Suppress_Elaboration_Warnings
(Id
);
743 End_Package_Scope
(Id
);
745 -- For the declaration of a library unit that is a remote types package,
746 -- check legality rules regarding availability of stream attributes for
747 -- types that contain non-remote access values. This subprogram performs
748 -- visibility tests that rely on the fact that we have exited the scope
752 Validate_RT_RAT_Component
(N
);
757 Write_Str
("<== package spec ");
758 Write_Name
(Chars
(Id
));
759 Write_Str
(" from ");
760 Write_Location
(Sloc
(N
));
763 end Analyze_Package_Declaration
;
765 -----------------------------------
766 -- Analyze_Package_Specification --
767 -----------------------------------
769 -- Note that this code is shared for the analysis of generic package specs
770 -- (see Sem_Ch12.Analyze_Generic_Package_Declaration for details).
772 procedure Analyze_Package_Specification
(N
: Node_Id
) is
773 Id
: constant Entity_Id
:= Defining_Entity
(N
);
774 Orig_Decl
: constant Node_Id
:= Original_Node
(Parent
(N
));
775 Vis_Decls
: constant List_Id
:= Visible_Declarations
(N
);
776 Priv_Decls
: constant List_Id
:= Private_Declarations
(N
);
779 Public_Child
: Boolean;
781 Private_With_Clauses_Installed
: Boolean := False;
782 -- In Ada 2005, private with_clauses are visible in the private part
783 -- of a nested package, even if it appears in the public part of the
784 -- enclosing package. This requires a separate step to install these
785 -- private_with_clauses, and remove them at the end of the nested
788 procedure Analyze_PPCs
(Decls
: List_Id
);
789 -- Given a list of declarations, go through looking for subprogram
790 -- specs, and for each one found, analyze any pre/postconditions that
791 -- are chained to the spec. This is the implementation of the late
792 -- visibility analysis for preconditions and postconditions in specs.
794 procedure Clear_Constants
(Id
: Entity_Id
; FE
: Entity_Id
);
795 -- Clears constant indications (Never_Set_In_Source, Constant_Value, and
796 -- Is_True_Constant) on all variables that are entities of Id, and on
797 -- the chain whose first element is FE. A recursive call is made for all
798 -- packages and generic packages.
800 procedure Generate_Parent_References
;
801 -- For a child unit, generate references to parent units, for
802 -- GPS navigation purposes.
804 function Is_Public_Child
(Child
, Unit
: Entity_Id
) return Boolean;
805 -- Child and Unit are entities of compilation units. True if Child
806 -- is a public child of Parent as defined in 10.1.1
808 procedure Inspect_Unchecked_Union_Completion
(Decls
: List_Id
);
809 -- Detects all incomplete or private type declarations having a known
810 -- discriminant part that are completed by an Unchecked_Union. Emits
811 -- the error message "Unchecked_Union may not complete discriminated
814 procedure Install_Parent_Private_Declarations
(Inst_Id
: Entity_Id
);
815 -- Given the package entity of a generic package instantiation or
816 -- formal package whose corresponding generic is a child unit, installs
817 -- the private declarations of each of the child unit's parents.
818 -- This has to be done at the point of entering the instance package's
819 -- private part rather than being done in Sem_Ch12.Install_Parent
820 -- (which is where the parents' visible declarations are installed).
826 procedure Analyze_PPCs
(Decls
: List_Id
) is
833 Decl
:= First
(Decls
);
834 while Present
(Decl
) loop
835 if Nkind
(Original_Node
(Decl
)) = N_Subprogram_Declaration
then
836 Spec
:= Specification
(Original_Node
(Decl
));
837 Sent
:= Defining_Unit_Name
(Spec
);
838 Prag
:= Spec_PPC_List
(Sent
);
839 while Present
(Prag
) loop
840 Analyze_PPC_In_Decl_Part
(Prag
, Sent
);
841 Prag
:= Next_Pragma
(Prag
);
849 ---------------------
850 -- Clear_Constants --
851 ---------------------
853 procedure Clear_Constants
(Id
: Entity_Id
; FE
: Entity_Id
) is
857 -- Ignore package renamings, not interesting and they can cause self
858 -- referential loops in the code below.
860 if Nkind
(Parent
(Id
)) = N_Package_Renaming_Declaration
then
864 -- Note: in the loop below, the check for Next_Entity pointing back
865 -- to the package entity may seem odd, but it is needed, because a
866 -- package can contain a renaming declaration to itself, and such
867 -- renamings are generated automatically within package instances.
870 while Present
(E
) and then E
/= Id
loop
871 if Is_Assignable
(E
) then
872 Set_Never_Set_In_Source
(E
, False);
873 Set_Is_True_Constant
(E
, False);
874 Set_Current_Value
(E
, Empty
);
875 Set_Is_Known_Null
(E
, False);
876 Set_Last_Assignment
(E
, Empty
);
878 if not Can_Never_Be_Null
(E
) then
879 Set_Is_Known_Non_Null
(E
, False);
882 elsif Is_Package_Or_Generic_Package
(E
) then
883 Clear_Constants
(E
, First_Entity
(E
));
884 Clear_Constants
(E
, First_Private_Entity
(E
));
891 --------------------------------
892 -- Generate_Parent_References --
893 --------------------------------
895 procedure Generate_Parent_References
is
896 Decl
: constant Node_Id
:= Parent
(N
);
899 if Id
= Cunit_Entity
(Main_Unit
)
900 or else Parent
(Decl
) = Library_Unit
(Cunit
(Main_Unit
))
902 Generate_Reference
(Id
, Scope
(Id
), 'k', False);
904 elsif not Nkind_In
(Unit
(Cunit
(Main_Unit
)), N_Subprogram_Body
,
907 -- If current unit is an ancestor of main unit, generate a
908 -- reference to its own parent.
912 Main_Spec
: Node_Id
:= Unit
(Cunit
(Main_Unit
));
915 if Nkind
(Main_Spec
) = N_Package_Body
then
916 Main_Spec
:= Unit
(Library_Unit
(Cunit
(Main_Unit
)));
919 U
:= Parent_Spec
(Main_Spec
);
920 while Present
(U
) loop
921 if U
= Parent
(Decl
) then
922 Generate_Reference
(Id
, Scope
(Id
), 'k', False);
925 elsif Nkind
(Unit
(U
)) = N_Package_Body
then
929 U
:= Parent_Spec
(Unit
(U
));
934 end Generate_Parent_References
;
936 ---------------------
937 -- Is_Public_Child --
938 ---------------------
940 function Is_Public_Child
(Child
, Unit
: Entity_Id
) return Boolean is
942 if not Is_Private_Descendant
(Child
) then
946 return not Private_Present
(
947 Parent
(Unit_Declaration_Node
(Child
)));
949 return Is_Public_Child
(Scope
(Child
), Unit
);
954 ----------------------------------------
955 -- Inspect_Unchecked_Union_Completion --
956 ----------------------------------------
958 procedure Inspect_Unchecked_Union_Completion
(Decls
: List_Id
) is
962 Decl
:= First
(Decls
);
963 while Present
(Decl
) loop
965 -- We are looking at an incomplete or private type declaration
966 -- with a known_discriminant_part whose full view is an
969 if Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
970 N_Private_Type_Declaration
)
971 and then Has_Discriminants
(Defining_Identifier
(Decl
))
972 and then Present
(Full_View
(Defining_Identifier
(Decl
)))
974 Is_Unchecked_Union
(Full_View
(Defining_Identifier
(Decl
)))
977 ("completion of discriminated partial view "
978 & "cannot be an Unchecked_Union",
979 Full_View
(Defining_Identifier
(Decl
)));
984 end Inspect_Unchecked_Union_Completion
;
986 -----------------------------------------
987 -- Install_Parent_Private_Declarations --
988 -----------------------------------------
990 procedure Install_Parent_Private_Declarations
(Inst_Id
: Entity_Id
) is
991 Inst_Par
: Entity_Id
;
999 Generic_Parent
(Specification
(Unit_Declaration_Node
(Inst_Par
)));
1000 while Present
(Gen_Par
) and then Is_Child_Unit
(Gen_Par
) loop
1001 Inst_Node
:= Get_Package_Instantiation_Node
(Inst_Par
);
1003 if Nkind_In
(Inst_Node
, N_Package_Instantiation
,
1004 N_Formal_Package_Declaration
)
1005 and then Nkind
(Name
(Inst_Node
)) = N_Expanded_Name
1007 Inst_Par
:= Entity
(Prefix
(Name
(Inst_Node
)));
1009 if Present
(Renamed_Entity
(Inst_Par
)) then
1010 Inst_Par
:= Renamed_Entity
(Inst_Par
);
1015 (Specification
(Unit_Declaration_Node
(Inst_Par
)));
1017 -- Install the private declarations and private use clauses
1018 -- of a parent instance of the child instance, unless the
1019 -- parent instance private declarations have already been
1020 -- installed earlier in Analyze_Package_Specification, which
1021 -- happens when a generic child is instantiated, and the
1022 -- instance is a child of the parent instance.
1024 -- Installing the use clauses of the parent instance twice
1025 -- is both unnecessary and wrong, because it would cause the
1026 -- clauses to be chained to themselves in the use clauses
1027 -- list of the scope stack entry. That in turn would cause
1028 -- an endless loop from End_Use_Clauses upon scope exit.
1030 -- The parent is now fully visible. It may be a hidden open
1031 -- scope if we are currently compiling some child instance
1032 -- declared within it, but while the current instance is being
1033 -- compiled the parent is immediately visible. In particular
1034 -- its entities must remain visible if a stack save/restore
1035 -- takes place through a call to Rtsfind.
1037 if Present
(Gen_Par
) then
1038 if not In_Private_Part
(Inst_Par
) then
1039 Install_Private_Declarations
(Inst_Par
);
1040 Set_Use
(Private_Declarations
1042 (Unit_Declaration_Node
(Inst_Par
))));
1043 Set_Is_Hidden_Open_Scope
(Inst_Par
, False);
1046 -- If we've reached the end of the generic instance parents,
1047 -- then finish off by looping through the nongeneric parents
1048 -- and installing their private declarations.
1051 while Present
(Inst_Par
)
1052 and then Inst_Par
/= Standard_Standard
1053 and then (not In_Open_Scopes
(Inst_Par
)
1054 or else not In_Private_Part
(Inst_Par
))
1056 Install_Private_Declarations
(Inst_Par
);
1057 Set_Use
(Private_Declarations
1059 (Unit_Declaration_Node
(Inst_Par
))));
1060 Inst_Par
:= Scope
(Inst_Par
);
1070 end Install_Parent_Private_Declarations
;
1072 -- Start of processing for Analyze_Package_Specification
1075 if Present
(Vis_Decls
) then
1076 Analyze_Declarations
(Vis_Decls
);
1077 Analyze_PPCs
(Vis_Decls
);
1080 -- Verify that incomplete types have received full declarations
1082 E
:= First_Entity
(Id
);
1083 while Present
(E
) loop
1084 if Ekind
(E
) = E_Incomplete_Type
1085 and then No
(Full_View
(E
))
1087 Error_Msg_N
("no declaration in visible part for incomplete}", E
);
1093 if Is_Remote_Call_Interface
(Id
)
1094 and then Nkind
(Parent
(Parent
(N
))) = N_Compilation_Unit
1096 Validate_RCI_Declarations
(Id
);
1099 -- Save global references in the visible declarations, before installing
1100 -- private declarations of parent unit if there is one, because the
1101 -- privacy status of types defined in the parent will change. This is
1102 -- only relevant for generic child units, but is done in all cases for
1105 if Ekind
(Id
) = E_Generic_Package
1106 and then Nkind
(Orig_Decl
) = N_Generic_Package_Declaration
1109 Orig_Spec
: constant Node_Id
:= Specification
(Orig_Decl
);
1110 Save_Priv
: constant List_Id
:= Private_Declarations
(Orig_Spec
);
1113 Set_Private_Declarations
(Orig_Spec
, Empty_List
);
1114 Save_Global_References
(Orig_Decl
);
1115 Set_Private_Declarations
(Orig_Spec
, Save_Priv
);
1119 -- If package is a public child unit, then make the private declarations
1120 -- of the parent visible.
1122 Public_Child
:= False;
1126 Pack_Decl
: Node_Id
;
1131 Par_Spec
:= Parent_Spec
(Parent
(N
));
1133 -- If the package is formal package of an enclosing generic, it is
1134 -- transformed into a local generic declaration, and compiled to make
1135 -- its spec available. We need to retrieve the original generic to
1136 -- determine whether it is a child unit, and install its parents.
1140 Nkind
(Original_Node
(Parent
(N
))) = N_Formal_Package_Declaration
1142 Par
:= Entity
(Name
(Original_Node
(Parent
(N
))));
1143 Par_Spec
:= Parent_Spec
(Unit_Declaration_Node
(Par
));
1146 if Present
(Par_Spec
) then
1147 Generate_Parent_References
;
1149 while Scope
(Par
) /= Standard_Standard
1150 and then Is_Public_Child
(Id
, Par
)
1151 and then In_Open_Scopes
(Par
)
1153 Public_Child
:= True;
1155 Install_Private_Declarations
(Par
);
1156 Install_Private_With_Clauses
(Par
);
1157 Pack_Decl
:= Unit_Declaration_Node
(Par
);
1158 Set_Use
(Private_Declarations
(Specification
(Pack_Decl
)));
1163 if Is_Compilation_Unit
(Id
) then
1164 Install_Private_With_Clauses
(Id
);
1167 -- The current compilation unit may include private with_clauses,
1168 -- which are visible in the private part of the current nested
1169 -- package, and have to be installed now. This is not done for
1170 -- nested instantiations, where the private with_clauses of the
1171 -- enclosing unit have no effect once the instantiation info is
1172 -- established and we start analyzing the package declaration.
1175 Comp_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
1177 if Is_Package_Or_Generic_Package
(Comp_Unit
)
1178 and then not In_Private_Part
(Comp_Unit
)
1179 and then not In_Instance
1181 Install_Private_With_Clauses
(Comp_Unit
);
1182 Private_With_Clauses_Installed
:= True;
1187 -- If this is a package associated with a generic instance or formal
1188 -- package, then the private declarations of each of the generic's
1189 -- parents must be installed at this point.
1191 if Is_Generic_Instance
(Id
) then
1192 Install_Parent_Private_Declarations
(Id
);
1195 -- Analyze private part if present. The flag In_Private_Part is reset
1196 -- in End_Package_Scope.
1198 L
:= Last_Entity
(Id
);
1200 if Present
(Priv_Decls
) then
1201 Set_In_Private_Part
(Id
);
1203 -- Upon entering a public child's private part, it may be necessary
1204 -- to declare subprograms that were derived in the package's visible
1205 -- part but not yet made visible.
1207 if Public_Child
then
1208 Declare_Inherited_Private_Subprograms
(Id
);
1211 Analyze_Declarations
(Priv_Decls
);
1212 Analyze_PPCs
(Priv_Decls
);
1214 -- Check the private declarations for incomplete deferred constants
1216 Inspect_Deferred_Constant_Completion
(Priv_Decls
);
1218 -- The first private entity is the immediate follower of the last
1219 -- visible entity, if there was one.
1222 Set_First_Private_Entity
(Id
, Next_Entity
(L
));
1224 Set_First_Private_Entity
(Id
, First_Entity
(Id
));
1227 -- There may be inherited private subprograms that need to be declared,
1228 -- even in the absence of an explicit private part. If there are any
1229 -- public declarations in the package and the package is a public child
1230 -- unit, then an implicit private part is assumed.
1232 elsif Present
(L
) and then Public_Child
then
1233 Set_In_Private_Part
(Id
);
1234 Declare_Inherited_Private_Subprograms
(Id
);
1235 Set_First_Private_Entity
(Id
, Next_Entity
(L
));
1238 E
:= First_Entity
(Id
);
1239 while Present
(E
) loop
1241 -- Check rule of 3.6(11), which in general requires waiting till all
1242 -- full types have been seen.
1244 if Ekind
(E
) = E_Record_Type
or else Ekind
(E
) = E_Array_Type
then
1245 Check_Aliased_Component_Types
(E
);
1248 -- Check preelaborable initialization for full type completing a
1249 -- private type for which pragma Preelaborable_Initialization given.
1252 and then Must_Have_Preelab_Init
(E
)
1253 and then not Has_Preelaborable_Initialization
(E
)
1256 ("full view of & does not have preelaborable initialization", E
);
1262 -- Ada 2005 (AI-216): The completion of an incomplete or private type
1263 -- declaration having a known_discriminant_part shall not be an
1264 -- Unchecked_Union type.
1266 if Present
(Vis_Decls
) then
1267 Inspect_Unchecked_Union_Completion
(Vis_Decls
);
1270 if Present
(Priv_Decls
) then
1271 Inspect_Unchecked_Union_Completion
(Priv_Decls
);
1274 if Ekind
(Id
) = E_Generic_Package
1275 and then Nkind
(Orig_Decl
) = N_Generic_Package_Declaration
1276 and then Present
(Priv_Decls
)
1278 -- Save global references in private declarations, ignoring the
1279 -- visible declarations that were processed earlier.
1282 Orig_Spec
: constant Node_Id
:= Specification
(Orig_Decl
);
1283 Save_Vis
: constant List_Id
:= Visible_Declarations
(Orig_Spec
);
1284 Save_Form
: constant List_Id
:=
1285 Generic_Formal_Declarations
(Orig_Decl
);
1288 Set_Visible_Declarations
(Orig_Spec
, Empty_List
);
1289 Set_Generic_Formal_Declarations
(Orig_Decl
, Empty_List
);
1290 Save_Global_References
(Orig_Decl
);
1291 Set_Generic_Formal_Declarations
(Orig_Decl
, Save_Form
);
1292 Set_Visible_Declarations
(Orig_Spec
, Save_Vis
);
1296 Process_End_Label
(N
, 'e', Id
);
1298 -- Remove private_with_clauses of enclosing compilation unit, if they
1301 if Private_With_Clauses_Installed
then
1302 Remove_Private_With_Clauses
(Cunit
(Current_Sem_Unit
));
1305 -- For the case of a library level package, we must go through all the
1306 -- entities clearing the indications that the value may be constant and
1307 -- not modified. Why? Because any client of this package may modify
1308 -- these values freely from anywhere. This also applies to any nested
1309 -- packages or generic packages.
1311 -- For now we unconditionally clear constants for packages that are
1312 -- instances of generic packages. The reason is that we do not have the
1313 -- body yet, and we otherwise think things are unreferenced when they
1314 -- are not. This should be fixed sometime (the effect is not terrible,
1315 -- we just lose some warnings, and also some cases of value propagation)
1318 if Is_Library_Level_Entity
(Id
)
1319 or else Is_Generic_Instance
(Id
)
1321 Clear_Constants
(Id
, First_Entity
(Id
));
1322 Clear_Constants
(Id
, First_Private_Entity
(Id
));
1324 end Analyze_Package_Specification
;
1326 --------------------------------------
1327 -- Analyze_Private_Type_Declaration --
1328 --------------------------------------
1330 procedure Analyze_Private_Type_Declaration
(N
: Node_Id
) is
1331 PF
: constant Boolean := Is_Pure
(Enclosing_Lib_Unit_Entity
);
1332 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1335 Generate_Definition
(Id
);
1336 Set_Is_Pure
(Id
, PF
);
1337 Init_Size_Align
(Id
);
1339 if not Is_Package_Or_Generic_Package
(Current_Scope
)
1340 or else In_Private_Part
(Current_Scope
)
1342 Error_Msg_N
("invalid context for private declaration", N
);
1345 New_Private_Type
(N
, Id
, N
);
1346 Set_Depends_On_Private
(Id
);
1347 end Analyze_Private_Type_Declaration
;
1349 ----------------------------------
1350 -- Check_Anonymous_Access_Types --
1351 ----------------------------------
1353 procedure Check_Anonymous_Access_Types
1354 (Spec_Id
: Entity_Id
;
1361 -- Itype references are only needed by gigi, to force elaboration of
1362 -- itypes. In the absence of code generation, they are not needed.
1364 if not Expander_Active
then
1368 E
:= First_Entity
(Spec_Id
);
1369 while Present
(E
) loop
1370 if Ekind
(E
) = E_Anonymous_Access_Type
1371 and then From_With_Type
(E
)
1373 IR
:= Make_Itype_Reference
(Sloc
(P_Body
));
1376 if No
(Declarations
(P_Body
)) then
1377 Set_Declarations
(P_Body
, New_List
(IR
));
1379 Prepend
(IR
, Declarations
(P_Body
));
1385 end Check_Anonymous_Access_Types
;
1387 -------------------------------------------
1388 -- Declare_Inherited_Private_Subprograms --
1389 -------------------------------------------
1391 procedure Declare_Inherited_Private_Subprograms
(Id
: Entity_Id
) is
1393 function Is_Primitive_Of
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
1394 -- Check whether an inherited subprogram is an operation of an untagged
1397 ---------------------
1398 -- Is_Primitive_Of --
1399 ---------------------
1401 function Is_Primitive_Of
(T
: Entity_Id
; S
: Entity_Id
) return Boolean is
1405 -- If the full view is a scalar type, the type is the anonymous base
1406 -- type, but the operation mentions the first subtype, so check the
1407 -- signature against the base type.
1409 if Base_Type
(Etype
(S
)) = Base_Type
(T
) then
1413 Formal
:= First_Formal
(S
);
1414 while Present
(Formal
) loop
1415 if Base_Type
(Etype
(Formal
)) = Base_Type
(T
) then
1419 Next_Formal
(Formal
);
1424 end Is_Primitive_Of
;
1431 Op_Elmt_2
: Elmt_Id
;
1432 Prim_Op
: Entity_Id
;
1433 New_Op
: Entity_Id
:= Empty
;
1434 Parent_Subp
: Entity_Id
;
1437 -- Start of processing for Declare_Inherited_Private_Subprograms
1440 E
:= First_Entity
(Id
);
1441 while Present
(E
) loop
1443 -- If the entity is a nonprivate type extension whose parent type
1444 -- is declared in an open scope, then the type may have inherited
1445 -- operations that now need to be made visible. Ditto if the entity
1446 -- is a formal derived type in a child unit.
1448 if ((Is_Derived_Type
(E
) and then not Is_Private_Type
(E
))
1450 (Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
1451 and then Is_Generic_Type
(E
)))
1452 and then In_Open_Scopes
(Scope
(Etype
(E
)))
1453 and then E
= Base_Type
(E
)
1455 if Is_Tagged_Type
(E
) then
1456 Op_List
:= Primitive_Operations
(E
);
1458 Tag
:= First_Tag_Component
(E
);
1460 Op_Elmt
:= First_Elmt
(Op_List
);
1461 while Present
(Op_Elmt
) loop
1462 Prim_Op
:= Node
(Op_Elmt
);
1464 -- Search primitives that are implicit operations with an
1465 -- internal name whose parent operation has a normal name.
1467 if Present
(Alias
(Prim_Op
))
1468 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= E
1469 and then not Comes_From_Source
(Prim_Op
)
1470 and then Is_Internal_Name
(Chars
(Prim_Op
))
1471 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
1473 Parent_Subp
:= Alias
(Prim_Op
);
1475 -- Case 1: Check if the type has also an explicit
1476 -- overriding for this primitive.
1478 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
1479 while Present
(Op_Elmt_2
) loop
1480 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
1481 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
1483 -- The private inherited operation has been
1484 -- overridden by an explicit subprogram: replace
1485 -- the former by the latter.
1487 New_Op
:= Node
(Op_Elmt_2
);
1488 Replace_Elmt
(Op_Elmt
, New_Op
);
1489 Remove_Elmt
(Op_List
, Op_Elmt_2
);
1490 Set_Is_Overriding_Operation
(New_Op
);
1491 Set_Overridden_Operation
(New_Op
, Parent_Subp
);
1493 -- We don't need to inherit its dispatching slot.
1494 -- Set_All_DT_Position has previously ensured that
1495 -- the same slot was assigned to the two primitives
1498 and then Present
(DTC_Entity
(New_Op
))
1499 and then Present
(DTC_Entity
(Prim_Op
))
1501 pragma Assert
(DT_Position
(New_Op
)
1502 = DT_Position
(Prim_Op
));
1506 goto Next_Primitive
;
1509 Next_Elmt
(Op_Elmt_2
);
1512 -- Case 2: We have not found any explicit overriding and
1513 -- hence we need to declare the operation (i.e., make it
1516 Derive_Subprogram
(New_Op
, Alias
(Prim_Op
), E
, Etype
(E
));
1518 -- Inherit the dispatching slot if E is already frozen
1521 and then Present
(DTC_Entity
(Alias
(Prim_Op
)))
1523 Set_DTC_Entity_Value
(E
, New_Op
);
1524 Set_DT_Position
(New_Op
,
1525 DT_Position
(Alias
(Prim_Op
)));
1529 (Is_Dispatching_Operation
(New_Op
)
1530 and then Node
(Last_Elmt
(Op_List
)) = New_Op
);
1532 -- Substitute the new operation for the old one in the
1533 -- type's primitive operations list. Since the new
1534 -- operation was also just added to the end of list,
1535 -- the last element must be removed.
1537 -- (Question: is there a simpler way of declaring the
1538 -- operation, say by just replacing the name of the
1539 -- earlier operation, reentering it in the in the symbol
1540 -- table (how?), and marking it as private???)
1542 Replace_Elmt
(Op_Elmt
, New_Op
);
1543 Remove_Last_Elmt
(Op_List
);
1547 Next_Elmt
(Op_Elmt
);
1550 -- Generate listing showing the contents of the dispatch table
1552 if Debug_Flag_ZZ
then
1557 -- Non-tagged type, scan forward to locate inherited hidden
1560 Prim_Op
:= Next_Entity
(E
);
1561 while Present
(Prim_Op
) loop
1562 if Is_Subprogram
(Prim_Op
)
1563 and then Present
(Alias
(Prim_Op
))
1564 and then not Comes_From_Source
(Prim_Op
)
1565 and then Is_Internal_Name
(Chars
(Prim_Op
))
1566 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
1567 and then Is_Primitive_Of
(E
, Prim_Op
)
1569 Derive_Subprogram
(New_Op
, Alias
(Prim_Op
), E
, Etype
(E
));
1572 Next_Entity
(Prim_Op
);
1579 end Declare_Inherited_Private_Subprograms
;
1581 -----------------------
1582 -- End_Package_Scope --
1583 -----------------------
1585 procedure End_Package_Scope
(P
: Entity_Id
) is
1587 Uninstall_Declarations
(P
);
1589 end End_Package_Scope
;
1591 ---------------------------
1592 -- Exchange_Declarations --
1593 ---------------------------
1595 procedure Exchange_Declarations
(Id
: Entity_Id
) is
1596 Full_Id
: constant Entity_Id
:= Full_View
(Id
);
1597 H1
: constant Entity_Id
:= Homonym
(Id
);
1598 Next1
: constant Entity_Id
:= Next_Entity
(Id
);
1603 -- If missing full declaration for type, nothing to exchange
1605 if No
(Full_Id
) then
1609 -- Otherwise complete the exchange, and preserve semantic links
1611 Next2
:= Next_Entity
(Full_Id
);
1612 H2
:= Homonym
(Full_Id
);
1614 -- Reset full declaration pointer to reflect the switched entities and
1615 -- readjust the next entity chains.
1617 Exchange_Entities
(Id
, Full_Id
);
1619 Set_Next_Entity
(Id
, Next1
);
1620 Set_Homonym
(Id
, H1
);
1622 Set_Full_View
(Full_Id
, Id
);
1623 Set_Next_Entity
(Full_Id
, Next2
);
1624 Set_Homonym
(Full_Id
, H2
);
1625 end Exchange_Declarations
;
1627 ----------------------------
1628 -- Install_Package_Entity --
1629 ----------------------------
1631 procedure Install_Package_Entity
(Id
: Entity_Id
) is
1633 if not Is_Internal
(Id
) then
1634 if Debug_Flag_E
then
1635 Write_Str
("Install: ");
1636 Write_Name
(Chars
(Id
));
1640 if not Is_Child_Unit
(Id
) then
1641 Set_Is_Immediately_Visible
(Id
);
1645 end Install_Package_Entity
;
1647 ----------------------------------
1648 -- Install_Private_Declarations --
1649 ----------------------------------
1651 procedure Install_Private_Declarations
(P
: Entity_Id
) is
1653 Priv_Elmt
: Elmt_Id
;
1658 -- First exchange declarations for private types, so that the full
1659 -- declaration is visible. For each private type, we check its
1660 -- Private_Dependents list and also exchange any subtypes of or derived
1661 -- types from it. Finally, if this is a Taft amendment type, the
1662 -- incomplete declaration is irrelevant, and we want to link the
1663 -- eventual full declaration with the original private one so we also
1664 -- skip the exchange.
1666 Id
:= First_Entity
(P
);
1667 while Present
(Id
) and then Id
/= First_Private_Entity
(P
) loop
1668 if Is_Private_Base_Type
(Id
)
1669 and then Comes_From_Source
(Full_View
(Id
))
1670 and then Present
(Full_View
(Id
))
1671 and then Scope
(Full_View
(Id
)) = Scope
(Id
)
1672 and then Ekind
(Full_View
(Id
)) /= E_Incomplete_Type
1674 -- If there is a use-type clause on the private type, set the
1675 -- full view accordingly.
1677 Set_In_Use
(Full_View
(Id
), In_Use
(Id
));
1678 Full
:= Full_View
(Id
);
1680 if Is_Private_Base_Type
(Full
)
1681 and then Has_Private_Declaration
(Full
)
1682 and then Nkind
(Parent
(Full
)) = N_Full_Type_Declaration
1683 and then In_Open_Scopes
(Scope
(Etype
(Full
)))
1684 and then In_Package_Body
(Current_Scope
)
1685 and then not Is_Private_Type
(Etype
(Full
))
1687 -- This is the completion of a private type by a derivation
1688 -- from another private type which is not private anymore. This
1689 -- can only happen in a package nested within a child package,
1690 -- when the parent type is defined in the parent unit. At this
1691 -- point the current type is not private either, and we have to
1692 -- install the underlying full view, which is now visible. Save
1693 -- the current full view as well, so that all views can be
1694 -- restored on exit. It may seem that after compiling the child
1695 -- body there are not environments to restore, but the back-end
1696 -- expects those links to be valid, and freeze nodes depend on
1699 if No
(Full_View
(Full
))
1700 and then Present
(Underlying_Full_View
(Full
))
1702 Set_Full_View
(Id
, Underlying_Full_View
(Full
));
1703 Set_Underlying_Full_View
(Id
, Full
);
1705 Set_Underlying_Full_View
(Full
, Empty
);
1706 Set_Is_Frozen
(Full_View
(Id
));
1710 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Id
));
1712 Exchange_Declarations
(Id
);
1713 Set_Is_Immediately_Visible
(Id
);
1715 while Present
(Priv_Elmt
) loop
1716 Priv
:= Node
(Priv_Elmt
);
1718 -- Before the exchange, verify that the presence of the
1719 -- Full_View field. It will be empty if the entity has already
1720 -- been installed due to a previous call.
1722 if Present
(Full_View
(Priv
))
1723 and then Is_Visible_Dependent
(Priv
)
1726 -- For each subtype that is swapped, we also swap the
1727 -- reference to it in Private_Dependents, to allow access
1728 -- to it when we swap them out in End_Package_Scope.
1730 Replace_Elmt
(Priv_Elmt
, Full_View
(Priv
));
1731 Exchange_Declarations
(Priv
);
1732 Set_Is_Immediately_Visible
1733 (Priv
, In_Open_Scopes
(Scope
(Priv
)));
1734 Set_Is_Potentially_Use_Visible
1735 (Priv
, Is_Potentially_Use_Visible
(Node
(Priv_Elmt
)));
1738 Next_Elmt
(Priv_Elmt
);
1745 -- Next make other declarations in the private part visible as well
1747 Id
:= First_Private_Entity
(P
);
1748 while Present
(Id
) loop
1749 Install_Package_Entity
(Id
);
1750 Set_Is_Hidden
(Id
, False);
1754 -- Indicate that the private part is currently visible, so it can be
1755 -- properly reset on exit.
1757 Set_In_Private_Part
(P
);
1758 end Install_Private_Declarations
;
1760 ----------------------------------
1761 -- Install_Visible_Declarations --
1762 ----------------------------------
1764 procedure Install_Visible_Declarations
(P
: Entity_Id
) is
1766 Last_Entity
: Entity_Id
;
1770 (Is_Package_Or_Generic_Package
(P
) or else Is_Record_Type
(P
));
1772 if Is_Package_Or_Generic_Package
(P
) then
1773 Last_Entity
:= First_Private_Entity
(P
);
1775 Last_Entity
:= Empty
;
1778 Id
:= First_Entity
(P
);
1779 while Present
(Id
) and then Id
/= Last_Entity
loop
1780 Install_Package_Entity
(Id
);
1783 end Install_Visible_Declarations
;
1785 --------------------------
1786 -- Is_Private_Base_Type --
1787 --------------------------
1789 function Is_Private_Base_Type
(E
: Entity_Id
) return Boolean is
1791 return Ekind
(E
) = E_Private_Type
1792 or else Ekind
(E
) = E_Limited_Private_Type
1793 or else Ekind
(E
) = E_Record_Type_With_Private
;
1794 end Is_Private_Base_Type
;
1796 --------------------------
1797 -- Is_Visible_Dependent --
1798 --------------------------
1800 function Is_Visible_Dependent
(Dep
: Entity_Id
) return Boolean
1802 S
: constant Entity_Id
:= Scope
(Dep
);
1805 -- Renamings created for actual types have the visibility of the actual
1807 if Ekind
(S
) = E_Package
1808 and then Is_Generic_Instance
(S
)
1809 and then (Is_Generic_Actual_Type
(Dep
)
1810 or else Is_Generic_Actual_Type
(Full_View
(Dep
)))
1814 elsif not (Is_Derived_Type
(Dep
))
1815 and then Is_Derived_Type
(Full_View
(Dep
))
1817 -- When instantiating a package body, the scope stack is empty, so
1818 -- check instead whether the dependent type is defined in the same
1819 -- scope as the instance itself.
1821 return In_Open_Scopes
(S
)
1822 or else (Is_Generic_Instance
(Current_Scope
)
1823 and then Scope
(Dep
) = Scope
(Current_Scope
));
1827 end Is_Visible_Dependent
;
1829 ----------------------------
1830 -- May_Need_Implicit_Body --
1831 ----------------------------
1833 procedure May_Need_Implicit_Body
(E
: Entity_Id
) is
1834 P
: constant Node_Id
:= Unit_Declaration_Node
(E
);
1835 S
: constant Node_Id
:= Parent
(P
);
1840 if not Has_Completion
(E
)
1841 and then Nkind
(P
) = N_Package_Declaration
1842 and then (Present
(Activation_Chain_Entity
(P
)) or else Has_RACW
(E
))
1845 Make_Package_Body
(Sloc
(E
),
1846 Defining_Unit_Name
=> Make_Defining_Identifier
(Sloc
(E
),
1847 Chars
=> Chars
(E
)),
1848 Declarations
=> New_List
);
1850 if Nkind
(S
) = N_Package_Specification
then
1851 if Present
(Private_Declarations
(S
)) then
1852 Decls
:= Private_Declarations
(S
);
1854 Decls
:= Visible_Declarations
(S
);
1857 Decls
:= Declarations
(S
);
1863 end May_Need_Implicit_Body
;
1865 ----------------------
1866 -- New_Private_Type --
1867 ----------------------
1869 procedure New_Private_Type
(N
: Node_Id
; Id
: Entity_Id
; Def
: Node_Id
) is
1873 if Limited_Present
(Def
) then
1874 Set_Ekind
(Id
, E_Limited_Private_Type
);
1876 Set_Ekind
(Id
, E_Private_Type
);
1880 Set_Has_Delayed_Freeze
(Id
);
1881 Set_Is_First_Subtype
(Id
);
1882 Init_Size_Align
(Id
);
1884 Set_Is_Constrained
(Id
,
1885 No
(Discriminant_Specifications
(N
))
1886 and then not Unknown_Discriminants_Present
(N
));
1888 -- Set tagged flag before processing discriminants, to catch illegal
1891 Set_Is_Tagged_Type
(Id
, Tagged_Present
(Def
));
1893 Set_Discriminant_Constraint
(Id
, No_Elist
);
1894 Set_Stored_Constraint
(Id
, No_Elist
);
1896 if Present
(Discriminant_Specifications
(N
)) then
1898 Process_Discriminants
(N
);
1901 elsif Unknown_Discriminants_Present
(N
) then
1902 Set_Has_Unknown_Discriminants
(Id
);
1905 Set_Private_Dependents
(Id
, New_Elmt_List
);
1907 if Tagged_Present
(Def
) then
1908 Set_Ekind
(Id
, E_Record_Type_With_Private
);
1909 Set_Primitive_Operations
(Id
, New_Elmt_List
);
1910 Set_Is_Abstract_Type
(Id
, Abstract_Present
(Def
));
1911 Set_Is_Limited_Record
(Id
, Limited_Present
(Def
));
1912 Set_Has_Delayed_Freeze
(Id
, True);
1914 -- Create a class-wide type with the same attributes
1916 Make_Class_Wide_Type
(Id
);
1918 elsif Abstract_Present
(Def
) then
1919 Error_Msg_N
("only a tagged type can be abstract", N
);
1921 end New_Private_Type
;
1923 ----------------------------
1924 -- Uninstall_Declarations --
1925 ----------------------------
1927 procedure Uninstall_Declarations
(P
: Entity_Id
) is
1928 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
1931 Priv_Elmt
: Elmt_Id
;
1932 Priv_Sub
: Entity_Id
;
1934 procedure Preserve_Full_Attributes
(Priv
, Full
: Entity_Id
);
1935 -- Copy to the private declaration the attributes of the full view that
1936 -- need to be available for the partial view also.
1938 function Type_In_Use
(T
: Entity_Id
) return Boolean;
1939 -- Check whether type or base type appear in an active use_type clause
1941 ------------------------------
1942 -- Preserve_Full_Attributes --
1943 ------------------------------
1945 procedure Preserve_Full_Attributes
(Priv
, Full
: Entity_Id
) is
1946 Priv_Is_Base_Type
: constant Boolean := Priv
= Base_Type
(Priv
);
1949 Set_Size_Info
(Priv
, (Full
));
1950 Set_RM_Size
(Priv
, RM_Size
(Full
));
1951 Set_Size_Known_At_Compile_Time
1952 (Priv
, Size_Known_At_Compile_Time
(Full
));
1953 Set_Is_Volatile
(Priv
, Is_Volatile
(Full
));
1954 Set_Treat_As_Volatile
(Priv
, Treat_As_Volatile
(Full
));
1955 Set_Is_Ada_2005_Only
(Priv
, Is_Ada_2005_Only
(Full
));
1956 Set_Has_Pragma_Unmodified
(Priv
, Has_Pragma_Unmodified
(Full
));
1957 Set_Has_Pragma_Unreferenced
(Priv
, Has_Pragma_Unreferenced
(Full
));
1958 Set_Has_Pragma_Unreferenced_Objects
1959 (Priv
, Has_Pragma_Unreferenced_Objects
1961 if Is_Unchecked_Union
(Full
) then
1962 Set_Is_Unchecked_Union
(Base_Type
(Priv
));
1964 -- Why is atomic not copied here ???
1966 if Referenced
(Full
) then
1967 Set_Referenced
(Priv
);
1970 if Priv_Is_Base_Type
then
1971 Set_Is_Controlled
(Priv
, Is_Controlled
(Base_Type
(Full
)));
1972 Set_Finalize_Storage_Only
(Priv
, Finalize_Storage_Only
1973 (Base_Type
(Full
)));
1974 Set_Has_Task
(Priv
, Has_Task
(Base_Type
(Full
)));
1975 Set_Has_Controlled_Component
(Priv
, Has_Controlled_Component
1976 (Base_Type
(Full
)));
1979 Set_Freeze_Node
(Priv
, Freeze_Node
(Full
));
1981 if Is_Tagged_Type
(Priv
)
1982 and then Is_Tagged_Type
(Full
)
1983 and then not Error_Posted
(Full
)
1985 if Priv_Is_Base_Type
then
1987 -- Ada 2005 (AI-345): The full view of a type implementing an
1988 -- interface can be a task type.
1990 -- type T is new I with private;
1992 -- task type T is new I with ...
1994 if Is_Interface
(Etype
(Priv
))
1995 and then Is_Concurrent_Type
(Base_Type
(Full
))
1997 -- Protect the frontend against previous errors
1999 if Present
(Corresponding_Record_Type
2002 Set_Access_Disp_Table
2003 (Priv
, Access_Disp_Table
2004 (Corresponding_Record_Type
(Base_Type
(Full
))));
2006 -- Generic context, or previous errors
2013 Set_Access_Disp_Table
2014 (Priv
, Access_Disp_Table
(Base_Type
(Full
)));
2018 if Is_Tagged_Type
(Priv
) then
2020 -- If the type is tagged, the tag itself must be available on
2021 -- the partial view, for expansion purposes.
2023 Set_First_Entity
(Priv
, First_Entity
(Full
));
2025 -- If there are discriminants in the partial view, these remain
2026 -- visible. Otherwise only the tag itself is visible, and there
2027 -- are no nameable components in the partial view.
2029 if No
(Last_Entity
(Priv
)) then
2030 Set_Last_Entity
(Priv
, First_Entity
(Priv
));
2034 Set_Has_Discriminants
(Priv
, Has_Discriminants
(Full
));
2036 if Has_Discriminants
(Full
) then
2037 Set_Discriminant_Constraint
(Priv
,
2038 Discriminant_Constraint
(Full
));
2041 end Preserve_Full_Attributes
;
2047 function Type_In_Use
(T
: Entity_Id
) return Boolean is
2049 return Scope
(Base_Type
(T
)) = P
2050 and then (In_Use
(T
) or else In_Use
(Base_Type
(T
)));
2053 -- Start of processing for Uninstall_Declarations
2056 Id
:= First_Entity
(P
);
2057 while Present
(Id
) and then Id
/= First_Private_Entity
(P
) loop
2058 if Debug_Flag_E
then
2059 Write_Str
("unlinking visible entity ");
2060 Write_Int
(Int
(Id
));
2064 -- On exit from the package scope, we must preserve the visibility
2065 -- established by use clauses in the current scope. Two cases:
2067 -- a) If the entity is an operator, it may be a primitive operator of
2068 -- a type for which there is a visible use-type clause.
2070 -- b) for other entities, their use-visibility is determined by a
2071 -- visible use clause for the package itself. For a generic instance,
2072 -- the instantiation of the formals appears in the visible part,
2073 -- but the formals are private and remain so.
2075 if Ekind
(Id
) = E_Function
2076 and then Is_Operator_Symbol_Name
(Chars
(Id
))
2077 and then not Is_Hidden
(Id
)
2078 and then not Error_Posted
(Id
)
2080 Set_Is_Potentially_Use_Visible
(Id
,
2082 or else Type_In_Use
(Etype
(Id
))
2083 or else Type_In_Use
(Etype
(First_Formal
(Id
)))
2084 or else (Present
(Next_Formal
(First_Formal
(Id
)))
2087 (Etype
(Next_Formal
(First_Formal
(Id
))))));
2089 if In_Use
(P
) and then not Is_Hidden
(Id
) then
2091 -- A child unit of a use-visible package remains use-visible
2092 -- only if it is itself a visible child unit. Otherwise it
2093 -- would remain visible in other contexts where P is use-
2094 -- visible, because once compiled it stays in the entity list
2095 -- of its parent unit.
2097 if Is_Child_Unit
(Id
) then
2098 Set_Is_Potentially_Use_Visible
(Id
,
2099 Is_Visible_Child_Unit
(Id
));
2101 Set_Is_Potentially_Use_Visible
(Id
);
2105 Set_Is_Potentially_Use_Visible
(Id
, False);
2109 -- Local entities are not immediately visible outside of the package
2111 Set_Is_Immediately_Visible
(Id
, False);
2113 -- If this is a private type with a full view (for example a local
2114 -- subtype of a private type declared elsewhere), ensure that the
2115 -- full view is also removed from visibility: it may be exposed when
2116 -- swapping views in an instantiation.
2119 and then Present
(Full_View
(Id
))
2121 Set_Is_Immediately_Visible
(Full_View
(Id
), False);
2124 if Is_Tagged_Type
(Id
) and then Ekind
(Id
) = E_Record_Type
then
2125 Check_Abstract_Overriding
(Id
);
2126 Check_Conventions
(Id
);
2129 if (Ekind
(Id
) = E_Private_Type
2130 or else Ekind
(Id
) = E_Limited_Private_Type
)
2131 and then No
(Full_View
(Id
))
2132 and then not Is_Generic_Type
(Id
)
2133 and then not Is_Derived_Type
(Id
)
2135 Error_Msg_N
("missing full declaration for private type&", Id
);
2137 elsif Ekind
(Id
) = E_Record_Type_With_Private
2138 and then not Is_Generic_Type
(Id
)
2139 and then No
(Full_View
(Id
))
2141 if Nkind
(Parent
(Id
)) = N_Private_Type_Declaration
then
2142 Error_Msg_N
("missing full declaration for private type&", Id
);
2145 ("missing full declaration for private extension", Id
);
2148 -- Case of constant, check for deferred constant declaration with
2149 -- no full view. Likely just a matter of a missing expression, or
2150 -- accidental use of the keyword constant.
2152 elsif Ekind
(Id
) = E_Constant
2154 -- OK if constant value present
2156 and then No
(Constant_Value
(Id
))
2158 -- OK if full view present
2160 and then No
(Full_View
(Id
))
2162 -- OK if imported, since that provides the completion
2164 and then not Is_Imported
(Id
)
2166 -- OK if object declaration replaced by renaming declaration as
2167 -- a result of OK_To_Rename processing (e.g. for concatenation)
2169 and then Nkind
(Parent
(Id
)) /= N_Object_Renaming_Declaration
2171 -- OK if object declaration with the No_Initialization flag set
2173 and then not (Nkind
(Parent
(Id
)) = N_Object_Declaration
2174 and then No_Initialization
(Parent
(Id
)))
2176 -- If no private declaration is present, we assume the user did
2177 -- not intend a deferred constant declaration and the problem
2178 -- is simply that the initializing expression is missing.
2180 if not Has_Private_Declaration
(Etype
(Id
)) then
2182 -- We assume that the user did not intend a deferred constant
2183 -- declaration, and the expression is just missing.
2186 ("constant declaration requires initialization expression",
2189 if Is_Limited_Type
(Etype
(Id
)) then
2191 ("\if variable intended, remove CONSTANT from declaration",
2195 -- Otherwise if a private declaration is present, then we are
2196 -- missing the full declaration for the deferred constant.
2200 ("missing full declaration for deferred constant (RM 7.4)",
2203 if Is_Limited_Type
(Etype
(Id
)) then
2205 ("\if variable intended, remove CONSTANT from declaration",
2214 -- If the specification was installed as the parent of a public child
2215 -- unit, the private declarations were not installed, and there is
2218 if not In_Private_Part
(P
) then
2221 Set_In_Private_Part
(P
, False);
2224 -- Make private entities invisible and exchange full and private
2225 -- declarations for private types. Id is now the first private entity
2228 while Present
(Id
) loop
2229 if Debug_Flag_E
then
2230 Write_Str
("unlinking private entity ");
2231 Write_Int
(Int
(Id
));
2235 if Is_Tagged_Type
(Id
) and then Ekind
(Id
) = E_Record_Type
then
2236 Check_Abstract_Overriding
(Id
);
2237 Check_Conventions
(Id
);
2240 Set_Is_Immediately_Visible
(Id
, False);
2242 if Is_Private_Base_Type
(Id
)
2243 and then Present
(Full_View
(Id
))
2245 Full
:= Full_View
(Id
);
2247 -- If the partial view is not declared in the visible part of the
2248 -- package (as is the case when it is a type derived from some
2249 -- other private type in the private part of the current package),
2250 -- no exchange takes place.
2253 or else List_Containing
(Parent
(Id
))
2254 /= Visible_Declarations
(Specification
(Decl
))
2259 -- The entry in the private part points to the full declaration,
2260 -- which is currently visible. Exchange them so only the private
2261 -- type declaration remains accessible, and link private and full
2262 -- declaration in the opposite direction. Before the actual
2263 -- exchange, we copy back attributes of the full view that must
2264 -- be available to the partial view too.
2266 Preserve_Full_Attributes
(Id
, Full
);
2268 Set_Is_Potentially_Use_Visible
(Id
, In_Use
(P
));
2270 if Is_Indefinite_Subtype
(Full
)
2271 and then not Is_Indefinite_Subtype
(Id
)
2274 ("full view of type must be definite subtype", Full
);
2277 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Id
));
2279 -- Swap out the subtypes and derived types of Id that were
2280 -- compiled in this scope, or installed previously by
2281 -- Install_Private_Declarations.
2283 -- Before we do the swap, we verify the presence of the Full_View
2284 -- field which may be empty due to a swap by a previous call to
2285 -- End_Package_Scope (e.g. from the freezing mechanism).
2287 while Present
(Priv_Elmt
) loop
2288 Priv_Sub
:= Node
(Priv_Elmt
);
2290 if Present
(Full_View
(Priv_Sub
)) then
2292 if Scope
(Priv_Sub
) = P
2293 or else not In_Open_Scopes
(Scope
(Priv_Sub
))
2295 Set_Is_Immediately_Visible
(Priv_Sub
, False);
2298 if Is_Visible_Dependent
(Priv_Sub
) then
2299 Preserve_Full_Attributes
2300 (Priv_Sub
, Full_View
(Priv_Sub
));
2301 Replace_Elmt
(Priv_Elmt
, Full_View
(Priv_Sub
));
2302 Exchange_Declarations
(Priv_Sub
);
2306 Next_Elmt
(Priv_Elmt
);
2309 -- Now restore the type itself to its private view
2311 Exchange_Declarations
(Id
);
2313 -- If we have installed an underlying full view for a type derived
2314 -- from a private type in a child unit, restore the proper views
2315 -- of private and full view. See corresponding code in
2316 -- Install_Private_Declarations.
2318 -- After the exchange, Full denotes the private type in the
2319 -- visible part of the package.
2321 if Is_Private_Base_Type
(Full
)
2322 and then Present
(Full_View
(Full
))
2323 and then Present
(Underlying_Full_View
(Full
))
2324 and then In_Package_Body
(Current_Scope
)
2326 Set_Full_View
(Full
, Underlying_Full_View
(Full
));
2327 Set_Underlying_Full_View
(Full
, Empty
);
2330 elsif Ekind
(Id
) = E_Incomplete_Type
2331 and then Comes_From_Source
(Id
)
2332 and then No
(Full_View
(Id
))
2334 -- Mark Taft amendment types. Verify that there are no primitive
2335 -- operations declared for the type (3.10.1(9)).
2337 Set_Has_Completion_In_Body
(Id
);
2344 Elmt
:= First_Elmt
(Private_Dependents
(Id
));
2345 while Present
(Elmt
) loop
2346 Subp
:= Node
(Elmt
);
2348 if Is_Overloadable
(Subp
) then
2350 ("type& must be completed in the private part",
2353 -- The return type of an access_to_function cannot be a
2354 -- Taft-amendment type.
2356 elsif Ekind
(Subp
) = E_Subprogram_Type
then
2357 if Etype
(Subp
) = Id
2359 (Is_Class_Wide_Type
(Etype
(Subp
))
2360 and then Etype
(Etype
(Subp
)) = Id
)
2363 ("type& must be completed in the private part",
2364 Associated_Node_For_Itype
(Subp
), Id
);
2372 elsif not Is_Child_Unit
(Id
)
2373 and then (not Is_Private_Type
(Id
)
2374 or else No
(Full_View
(Id
)))
2377 Set_Is_Potentially_Use_Visible
(Id
, False);
2383 end Uninstall_Declarations
;
2385 ------------------------
2386 -- Unit_Requires_Body --
2387 ------------------------
2389 function Unit_Requires_Body
(P
: Entity_Id
) return Boolean is
2393 -- Imported entity never requires body. Right now, only subprograms can
2394 -- be imported, but perhaps in the future we will allow import of
2397 if Is_Imported
(P
) then
2400 -- Body required if library package with pragma Elaborate_Body
2402 elsif Has_Pragma_Elaborate_Body
(P
) then
2405 -- Body required if subprogram
2407 elsif Is_Subprogram
(P
) or else Is_Generic_Subprogram
(P
) then
2410 -- Treat a block as requiring a body
2412 elsif Ekind
(P
) = E_Block
then
2415 elsif Ekind
(P
) = E_Package
2416 and then Nkind
(Parent
(P
)) = N_Package_Specification
2417 and then Present
(Generic_Parent
(Parent
(P
)))
2420 G_P
: constant Entity_Id
:= Generic_Parent
(Parent
(P
));
2422 if Has_Pragma_Elaborate_Body
(G_P
) then
2428 -- Otherwise search entity chain for entity requiring completion
2430 E
:= First_Entity
(P
);
2431 while Present
(E
) loop
2433 -- Always ignore child units. Child units get added to the entity
2434 -- list of a parent unit, but are not original entities of the
2435 -- parent, and so do not affect whether the parent needs a body.
2437 if Is_Child_Unit
(E
) then
2440 -- Ignore formal packages and their renamings
2442 elsif Ekind
(E
) = E_Package
2443 and then Nkind
(Original_Node
(Unit_Declaration_Node
(E
))) =
2444 N_Formal_Package_Declaration
2448 -- Otherwise test to see if entity requires a completion.
2449 -- Note that subprogram entities whose declaration does not come
2450 -- from source are ignored here on the basis that we assume the
2451 -- expander will provide an implicit completion at some point.
2453 elsif (Is_Overloadable
(E
)
2454 and then Ekind
(E
) /= E_Enumeration_Literal
2455 and then Ekind
(E
) /= E_Operator
2456 and then not Is_Abstract_Subprogram
(E
)
2457 and then not Has_Completion
(E
)
2458 and then Comes_From_Source
(Parent
(E
)))
2461 (Ekind
(E
) = E_Package
2463 and then not Has_Completion
(E
)
2464 and then Unit_Requires_Body
(E
))
2467 (Ekind
(E
) = E_Incomplete_Type
and then No
(Full_View
(E
)))
2470 ((Ekind
(E
) = E_Task_Type
or else
2471 Ekind
(E
) = E_Protected_Type
)
2472 and then not Has_Completion
(E
))
2475 (Ekind
(E
) = E_Generic_Package
and then E
/= P
2476 and then not Has_Completion
(E
)
2477 and then Unit_Requires_Body
(E
))
2480 (Is_Generic_Subprogram
(E
)
2481 and then not Has_Completion
(E
))
2486 -- Entity that does not require completion
2496 end Unit_Requires_Body
;