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 -- 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 Aspects
; use Aspects
;
32 with Atree
; use Atree
;
33 with Debug
; use Debug
;
34 with Einfo
; use Einfo
;
35 with Elists
; use Elists
;
36 with Errout
; use Errout
;
37 with Exp_Disp
; use Exp_Disp
;
38 with Exp_Dist
; use Exp_Dist
;
39 with Exp_Dbug
; use Exp_Dbug
;
41 with Lib
.Xref
; use Lib
.Xref
;
42 with Namet
; use Namet
;
43 with Nmake
; use Nmake
;
44 with Nlists
; use Nlists
;
46 with Output
; use Output
;
47 with Restrict
; use Restrict
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Cat
; use Sem_Cat
;
51 with Sem_Ch3
; use Sem_Ch3
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Ch10
; use Sem_Ch10
;
55 with Sem_Ch12
; use Sem_Ch12
;
56 with Sem_Ch13
; use Sem_Ch13
;
57 with Sem_Disp
; use Sem_Disp
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Util
; use Sem_Util
;
61 with Sem_Warn
; use Sem_Warn
;
62 with Snames
; use Snames
;
63 with Stand
; use Stand
;
64 with Sinfo
; use Sinfo
;
65 with Sinput
; use Sinput
;
67 with Uintp
; use Uintp
;
69 package body Sem_Ch7
is
71 -----------------------------------
72 -- Handling private declarations --
73 -----------------------------------
75 -- The principle that each entity has a single defining occurrence clashes
76 -- with the presence of two separate definitions for private types: the
77 -- first is the private type declaration, and the second is the full type
78 -- declaration. It is important that all references to the type point to
79 -- the same defining occurrence, namely the first one. To enforce the two
80 -- separate views of the entity, the corresponding information is swapped
81 -- between the two declarations. Outside of the package, the defining
82 -- occurrence only contains the private declaration information, while in
83 -- the private part and the body of the package the defining occurrence
84 -- contains the full declaration. To simplify the swap, the defining
85 -- occurrence that currently holds the private declaration points to the
86 -- full declaration. During semantic processing the defining occurrence
87 -- also points to a list of private dependents, that is to say access types
88 -- or composite types whose designated types or component types are
89 -- subtypes or derived types of the private type in question. After the
90 -- full declaration has been seen, the private dependents are updated to
91 -- indicate that they have full definitions.
93 -----------------------
94 -- Local Subprograms --
95 -----------------------
97 procedure Analyze_Package_Body_Helper
(N
: Node_Id
);
98 -- Does all the real work of Analyze_Package_Body
100 procedure Check_Anonymous_Access_Types
101 (Spec_Id
: Entity_Id
;
103 -- If the spec of a package has a limited_with_clause, it may declare
104 -- anonymous access types whose designated type is a limited view, such an
105 -- anonymous access return type for a function. This access type cannot be
106 -- elaborated in the spec itself, but it may need an itype reference if it
107 -- is used within a nested scope. In that case the itype reference is
108 -- created at the beginning of the corresponding package body and inserted
109 -- before other body declarations.
111 procedure Declare_Inherited_Private_Subprograms
(Id
: Entity_Id
);
112 -- Called upon entering the private part of a public child package and the
113 -- body of a nested package, to potentially declare certain inherited
114 -- subprograms that were inherited by types in the visible part, but whose
115 -- declaration was deferred because the parent operation was private and
116 -- not visible at that point. These subprograms are located by traversing
117 -- the visible part declarations looking for non-private type extensions
118 -- and then examining each of the primitive operations of such types to
119 -- find those that were inherited but declared with a special internal
120 -- name. Each such operation is now declared as an operation with a normal
121 -- name (using the name of the parent operation) and replaces the previous
122 -- implicit operation in the primitive operations list of the type. If the
123 -- inherited private operation has been overridden, then it's replaced by
124 -- the overriding operation.
126 procedure Install_Package_Entity
(Id
: Entity_Id
);
127 -- Supporting procedure for Install_{Visible,Private}_Declarations. Places
128 -- one entity on its visibility chain, and recurses on the visible part if
129 -- the entity is an inner package.
131 function Is_Private_Base_Type
(E
: Entity_Id
) return Boolean;
132 -- True for a private type that is not a subtype
134 function Is_Visible_Dependent
(Dep
: Entity_Id
) return Boolean;
135 -- If the private dependent is a private type whose full view is derived
136 -- from the parent type, its full properties are revealed only if we are in
137 -- the immediate scope of the private dependent. Should this predicate be
138 -- tightened further???
140 function Requires_Completion_In_Body
142 Pack_Id
: Entity_Id
) return Boolean;
143 -- Subsidiary to routines Unit_Requires_Body and Unit_Requires_Body_Info.
144 -- Determine whether entity Id declared in package spec Pack_Id requires
145 -- completion in a package body.
147 procedure Unit_Requires_Body_Info
(Pack_Id
: Entity_Id
);
148 -- Outputs info messages showing why package Pack_Id requires a body. The
149 -- caller has checked that the switch requesting this information is set,
150 -- and that the package does indeed require a body.
152 --------------------------
153 -- Analyze_Package_Body --
154 --------------------------
156 procedure Analyze_Package_Body
(N
: Node_Id
) is
157 Loc
: constant Source_Ptr
:= Sloc
(N
);
161 Write_Str
("==> package body ");
162 Write_Name
(Chars
(Defining_Entity
(N
)));
163 Write_Str
(" from ");
164 Write_Location
(Loc
);
169 -- The real work is split out into the helper, so it can do "return;"
170 -- without skipping the debug output.
172 Analyze_Package_Body_Helper
(N
);
176 Write_Str
("<== package body ");
177 Write_Name
(Chars
(Defining_Entity
(N
)));
178 Write_Str
(" from ");
179 Write_Location
(Loc
);
182 end Analyze_Package_Body
;
184 -----------------------------------
185 -- Analyze_Package_Body_Contract --
186 -----------------------------------
188 procedure Analyze_Package_Body_Contract
(Body_Id
: Entity_Id
) is
189 Spec_Id
: constant Entity_Id
:= Spec_Entity
(Body_Id
);
190 Mode
: SPARK_Mode_Type
;
194 -- Due to the timing of contract analysis, delayed pragmas may be
195 -- subject to the wrong SPARK_Mode, usually that of the enclosing
196 -- context. To remedy this, restore the original SPARK_Mode of the
197 -- related package body.
199 Save_SPARK_Mode_And_Set
(Body_Id
, Mode
);
201 Prag
:= Get_Pragma
(Body_Id
, Pragma_Refined_State
);
203 -- The analysis of pragma Refined_State detects whether the spec has
204 -- abstract states available for refinement.
206 if Present
(Prag
) then
207 Analyze_Refined_State_In_Decl_Part
(Prag
);
209 -- State refinement is required when the package declaration defines at
210 -- least one abstract state. Null states are not considered. Refinement
211 -- is not envorced when SPARK checks are turned off.
213 elsif SPARK_Mode
/= Off
214 and then Requires_State_Refinement
(Spec_Id
, Body_Id
)
216 Error_Msg_N
("package & requires state refinement", Spec_Id
);
219 -- Restore the SPARK_Mode of the enclosing context after all delayed
220 -- pragmas have been analyzed.
222 Restore_SPARK_Mode
(Mode
);
223 end Analyze_Package_Body_Contract
;
225 ---------------------------------
226 -- Analyze_Package_Body_Helper --
227 ---------------------------------
229 procedure Analyze_Package_Body_Helper
(N
: Node_Id
) is
230 procedure Hide_Public_Entities
(Decls
: List_Id
);
231 -- Attempt to hide all public entities found in declarative list Decls
232 -- by resetting their Is_Public flag to False depending on whether the
233 -- entities are not referenced by inlined or generic bodies. This kind
234 -- of processing is a conservative approximation and may still leave
235 -- certain entities externally visible.
237 procedure Install_Composite_Operations
(P
: Entity_Id
);
238 -- Composite types declared in the current scope may depend on types
239 -- that were private at the point of declaration, and whose full view
240 -- is now in scope. Indicate that the corresponding operations on the
241 -- composite type are available.
243 --------------------------
244 -- Hide_Public_Entities --
245 --------------------------
247 procedure Hide_Public_Entities
(Decls
: List_Id
) is
248 function Contains_Subp_Or_Const_Refs
(N
: Node_Id
) return Boolean;
249 -- Subsidiary to routine Has_Referencer. Determine whether a node
250 -- contains a reference to a subprogram or a non-static constant.
251 -- WARNING: this is a very expensive routine as it performs a full
254 function Has_Referencer
256 Top_Level
: Boolean := False) return Boolean;
257 -- A "referencer" is a construct which may reference a previous
258 -- declaration. Examine all declarations in list Decls in reverse
259 -- and determine whether once such referencer exists. All entities
260 -- in the range Last (Decls) .. Referencer are hidden from external
263 ---------------------------------
264 -- Contains_Subp_Or_Const_Refs --
265 ---------------------------------
267 function Contains_Subp_Or_Const_Refs
(N
: Node_Id
) return Boolean is
268 Reference_Seen
: Boolean := False;
270 function Is_Subp_Or_Const_Ref
271 (N
: Node_Id
) return Traverse_Result
;
272 -- Determine whether a node denotes a reference to a subprogram or
273 -- a non-static constant.
275 --------------------------
276 -- Is_Subp_Or_Const_Ref --
277 --------------------------
279 function Is_Subp_Or_Const_Ref
280 (N
: Node_Id
) return Traverse_Result
285 -- Detect a reference of the form
288 if Nkind
(N
) in N_Subprogram_Call
289 and then Is_Entity_Name
(Name
(N
))
291 Reference_Seen
:= True;
294 -- Detect a reference of the form
295 -- Subp'Some_Attribute
297 elsif Nkind
(N
) = N_Attribute_Reference
298 and then Is_Entity_Name
(Prefix
(N
))
299 and then Is_Subprogram
(Entity
(Prefix
(N
)))
301 Reference_Seen
:= True;
304 -- Detect the use of a non-static constant
306 elsif Is_Entity_Name
(N
)
307 and then Present
(Entity
(N
))
308 and then Ekind
(Entity
(N
)) = E_Constant
310 Val
:= Constant_Value
(Entity
(N
));
313 and then not Compile_Time_Known_Value
(Val
)
315 Reference_Seen
:= True;
321 end Is_Subp_Or_Const_Ref
;
323 procedure Find_Subp_Or_Const_Ref
is
324 new Traverse_Proc
(Is_Subp_Or_Const_Ref
);
326 -- Start of processing for Contains_Subp_Or_Const_Refs
329 Find_Subp_Or_Const_Ref
(N
);
331 return Reference_Seen
;
332 end Contains_Subp_Or_Const_Refs
;
338 function Has_Referencer
340 Top_Level
: Boolean := False) return Boolean
346 Has_Non_Subp_Const_Referencer
: Boolean := False;
347 -- Flag set for inlined subprogram bodies that do not contain
348 -- references to other subprograms or non-static constants.
355 -- Examine all declarations in reverse order, hiding all entities
356 -- from external visibility until a referencer has been found. The
357 -- algorithm recurses into nested packages.
359 Decl
:= Last
(Decls
);
360 while Present
(Decl
) loop
362 -- A stub is always considered a referencer
364 if Nkind
(Decl
) in N_Body_Stub
then
367 -- Package declaration
369 elsif Nkind
(Decl
) = N_Package_Declaration
370 and then not Has_Non_Subp_Const_Referencer
372 Spec
:= Specification
(Decl
);
374 -- Inspect the declarations of a non-generic package to try
375 -- and hide more entities from external visibility.
377 if not Is_Generic_Unit
(Defining_Entity
(Spec
)) then
378 if Has_Referencer
(Private_Declarations
(Spec
))
379 or else Has_Referencer
(Visible_Declarations
(Spec
))
387 elsif Nkind
(Decl
) = N_Package_Body
388 and then Present
(Corresponding_Spec
(Decl
))
390 Decl_Id
:= Corresponding_Spec
(Decl
);
392 -- A generic package body is a referencer. It would seem
393 -- that we only have to consider generics that can be
394 -- exported, i.e. where the corresponding spec is the
395 -- spec of the current package, but because of nested
396 -- instantiations, a fully private generic body may export
397 -- other private body entities. Furthermore, regardless of
398 -- whether there was a previous inlined subprogram, (an
399 -- instantiation of) the generic package may reference any
400 -- entity declared before it.
402 if Is_Generic_Unit
(Decl_Id
) then
405 -- Inspect the declarations of a non-generic package body to
406 -- try and hide more entities from external visibility.
408 elsif not Has_Non_Subp_Const_Referencer
409 and then Has_Referencer
(Declarations
(Decl
))
416 elsif Nkind
(Decl
) = N_Subprogram_Body
then
417 if Present
(Corresponding_Spec
(Decl
)) then
418 Decl_Id
:= Corresponding_Spec
(Decl
);
420 -- A generic subprogram body acts as a referencer
422 if Is_Generic_Unit
(Decl_Id
) then
426 -- An inlined subprogram body acts as a referencer
428 if Is_Inlined
(Decl_Id
)
429 or else Has_Pragma_Inline
(Decl_Id
)
431 -- Inspect the statements of the subprogram body
432 -- to determine whether the body references other
433 -- subprograms and/or non-static constants.
436 and then not Contains_Subp_Or_Const_Refs
(Decl
)
438 Has_Non_Subp_Const_Referencer
:= True;
444 -- Otherwise this is a stand alone subprogram body
447 Decl_Id
:= Defining_Entity
(Decl
);
449 -- An inlined body acts as a referencer. Note that an
450 -- inlined subprogram remains Is_Public as gigi requires
451 -- the flag to be set.
453 -- Note that we test Has_Pragma_Inline here rather than
454 -- Is_Inlined. We are compiling this for a client, and
455 -- it is the client who will decide if actual inlining
456 -- should occur, so we need to assume that the procedure
457 -- could be inlined for the purpose of accessing global
460 if Has_Pragma_Inline
(Decl_Id
) then
462 and then not Contains_Subp_Or_Const_Refs
(Decl
)
464 Has_Non_Subp_Const_Referencer
:= True;
469 Set_Is_Public
(Decl_Id
, False);
473 -- Exceptions, objects and renamings do not need to be public
474 -- if they are not followed by a construct which can reference
475 -- and export them. The Is_Public flag is reset on top level
476 -- entities only as anything nested is local to its context.
478 elsif Nkind_In
(Decl
, N_Exception_Declaration
,
479 N_Object_Declaration
,
480 N_Object_Renaming_Declaration
,
481 N_Subprogram_Declaration
,
482 N_Subprogram_Renaming_Declaration
)
484 Decl_Id
:= Defining_Entity
(Decl
);
487 and then not Is_Imported
(Decl_Id
)
488 and then not Is_Exported
(Decl_Id
)
489 and then No
(Interface_Name
(Decl_Id
))
491 (not Has_Non_Subp_Const_Referencer
492 or else Nkind
(Decl
) = N_Subprogram_Declaration
)
494 Set_Is_Public
(Decl_Id
, False);
501 return Has_Non_Subp_Const_Referencer
;
506 Discard
: Boolean := True;
507 pragma Unreferenced
(Discard
);
509 -- Start of processing for Hide_Public_Entities
512 -- The algorithm examines the top level declarations of a package
513 -- body in reverse looking for a construct that may export entities
514 -- declared prior to it. If such a scenario is encountered, then all
515 -- entities in the range Last (Decls) .. construct are hidden from
516 -- external visibility. Consider:
524 -- package body Pack is
525 -- External_Obj : ...; -- (1)
527 -- package body Gen is -- (2)
528 -- ... External_Obj ... -- (3)
531 -- Local_Obj : ...; -- (4)
534 -- In this example Local_Obj (4) must not be externally visible as
535 -- it cannot be exported by anything in Pack. The body of generic
536 -- package Gen (2) on the other hand acts as a "referencer" and may
537 -- export anything declared before it. Since the compiler does not
538 -- perform flow analysis, it is not possible to determine precisely
539 -- which entities will be exported when Gen is instantiated. In the
540 -- example above External_Obj (1) is exported at (3), but this may
541 -- not always be the case. The algorithm takes a conservative stance
542 -- and leaves entity External_Obj public.
544 Discard
:= Has_Referencer
(Decls
, Top_Level
=> True);
545 end Hide_Public_Entities
;
547 ----------------------------------
548 -- Install_Composite_Operations --
549 ----------------------------------
551 procedure Install_Composite_Operations
(P
: Entity_Id
) is
555 Id
:= First_Entity
(P
);
556 while Present
(Id
) loop
558 and then (Is_Limited_Composite
(Id
)
559 or else Is_Private_Composite
(Id
))
560 and then No
(Private_Component
(Id
))
562 Set_Is_Limited_Composite
(Id
, False);
563 Set_Is_Private_Composite
(Id
, False);
568 end Install_Composite_Operations
;
574 Last_Spec_Entity
: Entity_Id
;
579 -- Start of processing for Analyze_Package_Body_Helper
582 -- Find corresponding package specification, and establish the current
583 -- scope. The visible defining entity for the package is the defining
584 -- occurrence in the spec. On exit from the package body, all body
585 -- declarations are attached to the defining entity for the body, but
586 -- the later is never used for name resolution. In this fashion there
587 -- is only one visible entity that denotes the package.
589 -- Set Body_Id. Note that this will be reset to point to the generic
590 -- copy later on in the generic case.
592 Body_Id
:= Defining_Entity
(N
);
594 -- Body is body of package instantiation. Corresponding spec has already
597 if Present
(Corresponding_Spec
(N
)) then
598 Spec_Id
:= Corresponding_Spec
(N
);
599 Pack_Decl
:= Unit_Declaration_Node
(Spec_Id
);
602 Spec_Id
:= Current_Entity_In_Scope
(Defining_Entity
(N
));
605 and then Is_Package_Or_Generic_Package
(Spec_Id
)
607 Pack_Decl
:= Unit_Declaration_Node
(Spec_Id
);
609 if Nkind
(Pack_Decl
) = N_Package_Renaming_Declaration
then
610 Error_Msg_N
("cannot supply body for package renaming", N
);
613 elsif Present
(Corresponding_Body
(Pack_Decl
)) then
614 Error_Msg_N
("redefinition of package body", N
);
619 Error_Msg_N
("missing specification for package body", N
);
623 if Is_Package_Or_Generic_Package
(Spec_Id
)
624 and then (Scope
(Spec_Id
) = Standard_Standard
625 or else Is_Child_Unit
(Spec_Id
))
626 and then not Unit_Requires_Body
(Spec_Id
)
628 if Ada_Version
= Ada_83
then
630 ("optional package body (not allowed in Ada 95)??", N
);
632 Error_Msg_N
("spec of this package does not allow a body", N
);
637 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
638 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
640 if Is_Child_Unit
(Spec_Id
) then
641 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
643 ("body of child unit& cannot be an inner package", N
, Spec_Id
);
646 Set_Is_Child_Unit
(Body_Id
);
649 -- Generic package case
651 if Ekind
(Spec_Id
) = E_Generic_Package
then
653 -- Disable expansion and perform semantic analysis on copy. The
654 -- unannotated body will be used in all instantiations.
656 Body_Id
:= Defining_Entity
(N
);
657 Set_Ekind
(Body_Id
, E_Package_Body
);
658 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
659 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
660 Set_Body_Entity
(Spec_Id
, Body_Id
);
661 Set_Spec_Entity
(Body_Id
, Spec_Id
);
663 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
666 -- Once the contents of the generic copy and the template are
667 -- swapped, do the same for their respective aspect specifications.
669 Exchange_Aspects
(N
, New_N
);
671 -- Update Body_Id to point to the copied node for the remainder of
674 Body_Id
:= Defining_Entity
(N
);
678 -- The Body_Id is that of the copied node in the generic case, the
679 -- current node otherwise. Note that N was rewritten above, so we must
680 -- be sure to get the latest Body_Id value.
682 Set_Ekind
(Body_Id
, E_Package_Body
);
683 Set_Body_Entity
(Spec_Id
, Body_Id
);
684 Set_Spec_Entity
(Body_Id
, Spec_Id
);
685 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
687 -- Defining name for the package body is not a visible entity: Only the
688 -- defining name for the declaration is visible.
690 Set_Etype
(Body_Id
, Standard_Void_Type
);
691 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
692 Set_Corresponding_Spec
(N
, Spec_Id
);
693 Set_Corresponding_Body
(Pack_Decl
, Body_Id
);
695 -- The body entity is not used for semantics or code generation, but
696 -- it is attached to the entity list of the enclosing scope to simplify
697 -- the listing of back-annotations for the types it main contain.
699 if Scope
(Spec_Id
) /= Standard_Standard
then
700 Append_Entity
(Body_Id
, Scope
(Spec_Id
));
703 -- Indicate that we are currently compiling the body of the package
705 Set_In_Package_Body
(Spec_Id
);
706 Set_Has_Completion
(Spec_Id
);
707 Last_Spec_Entity
:= Last_Entity
(Spec_Id
);
709 if Has_Aspects
(N
) then
710 Analyze_Aspect_Specifications
(N
, Body_Id
);
713 Push_Scope
(Spec_Id
);
715 -- Set SPARK_Mode only for non-generic package
717 if Ekind
(Spec_Id
) = E_Package
then
719 -- Set SPARK_Mode from context
721 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
722 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
724 -- Set elaboration code SPARK mode the same for now
726 Set_SPARK_Aux_Pragma
(Body_Id
, SPARK_Pragma
(Body_Id
));
727 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
730 -- Inherit the "ghostness" of the subprogram spec. Note that this
731 -- property is not directly inherited as the body may be subject to a
732 -- different Ghost assertion policy.
734 if Is_Ghost_Entity
(Spec_Id
) or else Within_Ghost_Scope
then
735 Set_Is_Ghost_Entity
(Body_Id
);
737 -- The Ghost policy in effect at the point of declaration and at the
738 -- point of completion must match (SPARK RM 6.9(15)).
740 Check_Ghost_Completion
(Spec_Id
, Body_Id
);
743 Set_Categorization_From_Pragmas
(N
);
745 Install_Visible_Declarations
(Spec_Id
);
746 Install_Private_Declarations
(Spec_Id
);
747 Install_Private_With_Clauses
(Spec_Id
);
748 Install_Composite_Operations
(Spec_Id
);
750 Check_Anonymous_Access_Types
(Spec_Id
, N
);
752 if Ekind
(Spec_Id
) = E_Generic_Package
then
753 Set_Use
(Generic_Formal_Declarations
(Pack_Decl
));
756 Set_Use
(Visible_Declarations
(Specification
(Pack_Decl
)));
757 Set_Use
(Private_Declarations
(Specification
(Pack_Decl
)));
759 -- This is a nested package, so it may be necessary to declare certain
760 -- inherited subprograms that are not yet visible because the parent
761 -- type's subprograms are now visible.
763 if Ekind
(Scope
(Spec_Id
)) = E_Package
764 and then Scope
(Spec_Id
) /= Standard_Standard
766 Declare_Inherited_Private_Subprograms
(Spec_Id
);
769 if Present
(Declarations
(N
)) then
770 Analyze_Declarations
(Declarations
(N
));
771 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
774 -- Verify that the SPARK_Mode of the body agrees with that of its spec
776 if Present
(SPARK_Pragma
(Body_Id
)) then
777 if Present
(SPARK_Aux_Pragma
(Spec_Id
)) then
778 if Get_SPARK_Mode_From_Pragma
(SPARK_Aux_Pragma
(Spec_Id
)) = Off
780 Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Body_Id
)) = On
782 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
783 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
784 Error_Msg_Sloc
:= Sloc
(SPARK_Aux_Pragma
(Spec_Id
));
786 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
790 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
791 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
792 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
794 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
798 -- Analyze_Declarations has caused freezing of all types. Now generate
799 -- bodies for RACW primitives and stream attributes, if any.
801 if Ekind
(Spec_Id
) = E_Package
and then Has_RACW
(Spec_Id
) then
803 -- Attach subprogram bodies to support RACWs declared in spec
805 Append_RACW_Bodies
(Declarations
(N
), Spec_Id
);
806 Analyze_List
(Declarations
(N
));
809 HSS
:= Handled_Statement_Sequence
(N
);
811 if Present
(HSS
) then
812 Process_End_Label
(HSS
, 't', Spec_Id
);
815 -- Check that elaboration code in a preelaborable package body is
816 -- empty other than null statements and labels (RM 10.2.1(6)).
818 Validate_Null_Statement_Sequence
(N
);
821 Validate_Categorization_Dependency
(N
, Spec_Id
);
822 Check_Completion
(Body_Id
);
824 -- Generate start of body reference. Note that we do this fairly late,
825 -- because the call will use In_Extended_Main_Source_Unit as a check,
826 -- and we want to make sure that Corresponding_Stub links are set
828 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
830 -- For a generic package, collect global references and mark them on
831 -- the original body so that they are not resolved again at the point
834 if Ekind
(Spec_Id
) /= E_Package
then
835 Save_Global_References
(Original_Node
(N
));
839 -- The entities of the package body have so far been chained onto the
840 -- declaration chain for the spec. That's been fine while we were in the
841 -- body, since we wanted them to be visible, but now that we are leaving
842 -- the package body, they are no longer visible, so we remove them from
843 -- the entity chain of the package spec entity, and copy them to the
844 -- entity chain of the package body entity, where they will never again
847 if Present
(Last_Spec_Entity
) then
848 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Spec_Entity
));
849 Set_Next_Entity
(Last_Spec_Entity
, Empty
);
850 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
851 Set_Last_Entity
(Spec_Id
, Last_Spec_Entity
);
854 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
855 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
856 Set_First_Entity
(Spec_Id
, Empty
);
857 Set_Last_Entity
(Spec_Id
, Empty
);
860 End_Package_Scope
(Spec_Id
);
862 -- All entities declared in body are not visible
868 E
:= First_Entity
(Body_Id
);
869 while Present
(E
) loop
870 Set_Is_Immediately_Visible
(E
, False);
871 Set_Is_Potentially_Use_Visible
(E
, False);
874 -- Child units may appear on the entity list (e.g. if they appear
875 -- in the context of a subunit) but they are not body entities.
877 if not Is_Child_Unit
(E
) then
878 Set_Is_Package_Body_Entity
(E
);
885 Check_References
(Body_Id
);
887 -- For a generic unit, check that the formal parameters are referenced,
888 -- and that local variables are used, as for regular packages.
890 if Ekind
(Spec_Id
) = E_Generic_Package
then
891 Check_References
(Spec_Id
);
894 -- At this point all entities of the package body are externally visible
895 -- to the linker as their Is_Public flag is set to True. This proactive
896 -- approach is necessary because an inlined or a generic body for which
897 -- code is generated in other units may need to see these entities. Cut
898 -- down the number of global symbols that do not neet public visibility
899 -- as this has two beneficial effects:
900 -- (1) It makes the compilation process more efficient.
901 -- (2) It gives the code generatormore freedom to optimize within each
902 -- unit, especially subprograms.
904 -- This is done only for top level library packages or child units as
905 -- the algorithm does a top down traversal of the package body.
907 if (Scope
(Spec_Id
) = Standard_Standard
or else Is_Child_Unit
(Spec_Id
))
908 and then not Is_Generic_Unit
(Spec_Id
)
910 Hide_Public_Entities
(Declarations
(N
));
913 -- If expander is not active, then here is where we turn off the
914 -- In_Package_Body flag, otherwise it is turned off at the end of the
915 -- corresponding expansion routine. If this is an instance body, we need
916 -- to qualify names of local entities, because the body may have been
917 -- compiled as a preliminary to another instantiation.
919 if not Expander_Active
then
920 Set_In_Package_Body
(Spec_Id
, False);
922 if Is_Generic_Instance
(Spec_Id
)
923 and then Operating_Mode
= Generate_Code
925 Qualify_Entity_Names
(N
);
928 end Analyze_Package_Body_Helper
;
930 ------------------------------
931 -- Analyze_Package_Contract --
932 ------------------------------
934 procedure Analyze_Package_Contract
(Pack_Id
: Entity_Id
) is
935 Mode
: SPARK_Mode_Type
;
939 -- Due to the timing of contract analysis, delayed pragmas may be
940 -- subject to the wrong SPARK_Mode, usually that of the enclosing
941 -- context. To remedy this, restore the original SPARK_Mode of the
944 Save_SPARK_Mode_And_Set
(Pack_Id
, Mode
);
946 -- Analyze the initialization related pragmas. Initializes must come
947 -- before Initial_Condition due to item dependencies.
949 Prag
:= Get_Pragma
(Pack_Id
, Pragma_Initializes
);
951 if Present
(Prag
) then
952 Analyze_Initializes_In_Decl_Part
(Prag
);
955 Prag
:= Get_Pragma
(Pack_Id
, Pragma_Initial_Condition
);
957 if Present
(Prag
) then
958 Analyze_Initial_Condition_In_Decl_Part
(Prag
);
961 -- Check whether the lack of indicator Part_Of agrees with the placement
962 -- of the package instantiation with respect to the state space.
964 if Is_Generic_Instance
(Pack_Id
) then
965 Prag
:= Get_Pragma
(Pack_Id
, Pragma_Part_Of
);
968 Check_Missing_Part_Of
(Pack_Id
);
972 -- Restore the SPARK_Mode of the enclosing context after all delayed
973 -- pragmas have been analyzed.
975 Restore_SPARK_Mode
(Mode
);
976 end Analyze_Package_Contract
;
978 ---------------------------------
979 -- Analyze_Package_Declaration --
980 ---------------------------------
982 procedure Analyze_Package_Declaration
(N
: Node_Id
) is
983 Id
: constant Node_Id
:= Defining_Entity
(N
);
986 -- True when in the context of a declared pure library unit
988 Body_Required
: Boolean;
989 -- True when this package declaration requires a corresponding body
992 -- True when this package declaration is not a nested declaration
996 Write_Str
("==> package spec ");
997 Write_Name
(Chars
(Id
));
998 Write_Str
(" from ");
999 Write_Location
(Sloc
(N
));
1004 Generate_Definition
(Id
);
1006 Set_Ekind
(Id
, E_Package
);
1007 Set_Etype
(Id
, Standard_Void_Type
);
1008 Set_Contract
(Id
, Make_Contract
(Sloc
(Id
)));
1010 -- Set SPARK_Mode from context only for non-generic package
1012 if Ekind
(Id
) = E_Package
then
1013 Set_SPARK_Pragma
(Id
, SPARK_Mode_Pragma
);
1014 Set_SPARK_Aux_Pragma
(Id
, SPARK_Mode_Pragma
);
1015 Set_SPARK_Pragma_Inherited
(Id
, True);
1016 Set_SPARK_Aux_Pragma_Inherited
(Id
, True);
1019 -- Analyze aspect specifications immediately, since we need to recognize
1020 -- things like Pure early enough to diagnose violations during analysis.
1022 if Has_Aspects
(N
) then
1023 Analyze_Aspect_Specifications
(N
, Id
);
1026 -- Ada 2005 (AI-217): Check if the package has been illegally named
1027 -- in a limited-with clause of its own context. In this case the error
1028 -- has been previously notified by Analyze_Context.
1030 -- limited with Pkg; -- ERROR
1031 -- package Pkg is ...
1033 if From_Limited_With
(Id
) then
1039 PF
:= Is_Pure
(Enclosing_Lib_Unit_Entity
);
1040 Set_Is_Pure
(Id
, PF
);
1042 Set_Categorization_From_Pragmas
(N
);
1044 Analyze
(Specification
(N
));
1045 Validate_Categorization_Dependency
(N
, Id
);
1047 Body_Required
:= Unit_Requires_Body
(Id
);
1049 -- When this spec does not require an explicit body, we know that there
1050 -- are no entities requiring completion in the language sense; we call
1051 -- Check_Completion here only to ensure that any nested package
1052 -- declaration that requires an implicit body gets one. (In the case
1053 -- where a body is required, Check_Completion is called at the end of
1054 -- the body's declarative part.)
1056 if not Body_Required
then
1060 Comp_Unit
:= Nkind
(Parent
(N
)) = N_Compilation_Unit
;
1063 -- Set Body_Required indication on the compilation unit node, and
1064 -- determine whether elaboration warnings may be meaningful on it.
1066 Set_Body_Required
(Parent
(N
), Body_Required
);
1068 if not Body_Required
then
1069 Set_Suppress_Elaboration_Warnings
(Id
);
1074 End_Package_Scope
(Id
);
1076 -- For the declaration of a library unit that is a remote types package,
1077 -- check legality rules regarding availability of stream attributes for
1078 -- types that contain non-remote access values. This subprogram performs
1079 -- visibility tests that rely on the fact that we have exited the scope
1083 Validate_RT_RAT_Component
(N
);
1086 if Debug_Flag_C
then
1088 Write_Str
("<== package spec ");
1089 Write_Name
(Chars
(Id
));
1090 Write_Str
(" from ");
1091 Write_Location
(Sloc
(N
));
1094 end Analyze_Package_Declaration
;
1096 -----------------------------------
1097 -- Analyze_Package_Specification --
1098 -----------------------------------
1100 -- Note that this code is shared for the analysis of generic package specs
1101 -- (see Sem_Ch12.Analyze_Generic_Package_Declaration for details).
1103 procedure Analyze_Package_Specification
(N
: Node_Id
) is
1104 Id
: constant Entity_Id
:= Defining_Entity
(N
);
1105 Orig_Decl
: constant Node_Id
:= Original_Node
(Parent
(N
));
1106 Vis_Decls
: constant List_Id
:= Visible_Declarations
(N
);
1107 Priv_Decls
: constant List_Id
:= Private_Declarations
(N
);
1110 Public_Child
: Boolean;
1112 Private_With_Clauses_Installed
: Boolean := False;
1113 -- In Ada 2005, private with_clauses are visible in the private part
1114 -- of a nested package, even if it appears in the public part of the
1115 -- enclosing package. This requires a separate step to install these
1116 -- private_with_clauses, and remove them at the end of the nested
1119 procedure Check_One_Tagged_Type_Or_Extension_At_Most
;
1120 -- Issue an error in SPARK mode if a package specification contains
1121 -- more than one tagged type or type extension.
1123 procedure Clear_Constants
(Id
: Entity_Id
; FE
: Entity_Id
);
1124 -- Clears constant indications (Never_Set_In_Source, Constant_Value, and
1125 -- Is_True_Constant) on all variables that are entities of Id, and on
1126 -- the chain whose first element is FE. A recursive call is made for all
1127 -- packages and generic packages.
1129 procedure Generate_Parent_References
;
1130 -- For a child unit, generate references to parent units, for
1131 -- GPS navigation purposes.
1133 function Is_Public_Child
(Child
, Unit
: Entity_Id
) return Boolean;
1134 -- Child and Unit are entities of compilation units. True if Child
1135 -- is a public child of Parent as defined in 10.1.1
1137 procedure Inspect_Unchecked_Union_Completion
(Decls
: List_Id
);
1138 -- Reject completion of an incomplete or private type declarations
1139 -- having a known discriminant part by an unchecked union.
1141 procedure Install_Parent_Private_Declarations
(Inst_Id
: Entity_Id
);
1142 -- Given the package entity of a generic package instantiation or
1143 -- formal package whose corresponding generic is a child unit, installs
1144 -- the private declarations of each of the child unit's parents.
1145 -- This has to be done at the point of entering the instance package's
1146 -- private part rather than being done in Sem_Ch12.Install_Parent
1147 -- (which is where the parents' visible declarations are installed).
1149 ------------------------------------------------
1150 -- Check_One_Tagged_Type_Or_Extension_At_Most --
1151 ------------------------------------------------
1153 procedure Check_One_Tagged_Type_Or_Extension_At_Most
is
1156 procedure Check_Decls
(Decls
: List_Id
);
1157 -- Check that either Previous is Empty and Decls does not contain
1158 -- more than one tagged type or type extension, or Previous is
1159 -- already set and Decls contains no tagged type or type extension.
1165 procedure Check_Decls
(Decls
: List_Id
) is
1169 Decl
:= First
(Decls
);
1170 while Present
(Decl
) loop
1171 if Nkind
(Decl
) = N_Full_Type_Declaration
1172 and then Is_Tagged_Type
(Defining_Identifier
(Decl
))
1174 if No
(Previous
) then
1178 Error_Msg_Sloc
:= Sloc
(Previous
);
1179 Check_SPARK_05_Restriction
1180 ("at most one tagged type or type extension allowed",
1181 "\\ previous declaration#",
1190 -- Start of processing for Check_One_Tagged_Type_Or_Extension_At_Most
1194 Check_Decls
(Vis_Decls
);
1196 if Present
(Priv_Decls
) then
1197 Check_Decls
(Priv_Decls
);
1199 end Check_One_Tagged_Type_Or_Extension_At_Most
;
1201 ---------------------
1202 -- Clear_Constants --
1203 ---------------------
1205 procedure Clear_Constants
(Id
: Entity_Id
; FE
: Entity_Id
) is
1209 -- Ignore package renamings, not interesting and they can cause self
1210 -- referential loops in the code below.
1212 if Nkind
(Parent
(Id
)) = N_Package_Renaming_Declaration
then
1216 -- Note: in the loop below, the check for Next_Entity pointing back
1217 -- to the package entity may seem odd, but it is needed, because a
1218 -- package can contain a renaming declaration to itself, and such
1219 -- renamings are generated automatically within package instances.
1222 while Present
(E
) and then E
/= Id
loop
1223 if Is_Assignable
(E
) then
1224 Set_Never_Set_In_Source
(E
, False);
1225 Set_Is_True_Constant
(E
, False);
1226 Set_Current_Value
(E
, Empty
);
1227 Set_Is_Known_Null
(E
, False);
1228 Set_Last_Assignment
(E
, Empty
);
1230 if not Can_Never_Be_Null
(E
) then
1231 Set_Is_Known_Non_Null
(E
, False);
1234 elsif Is_Package_Or_Generic_Package
(E
) then
1235 Clear_Constants
(E
, First_Entity
(E
));
1236 Clear_Constants
(E
, First_Private_Entity
(E
));
1241 end Clear_Constants
;
1243 --------------------------------
1244 -- Generate_Parent_References --
1245 --------------------------------
1247 procedure Generate_Parent_References
is
1248 Decl
: constant Node_Id
:= Parent
(N
);
1251 if Id
= Cunit_Entity
(Main_Unit
)
1252 or else Parent
(Decl
) = Library_Unit
(Cunit
(Main_Unit
))
1254 Generate_Reference
(Id
, Scope
(Id
), 'k', False);
1256 elsif not Nkind_In
(Unit
(Cunit
(Main_Unit
)), N_Subprogram_Body
,
1259 -- If current unit is an ancestor of main unit, generate a
1260 -- reference to its own parent.
1264 Main_Spec
: Node_Id
:= Unit
(Cunit
(Main_Unit
));
1267 if Nkind
(Main_Spec
) = N_Package_Body
then
1268 Main_Spec
:= Unit
(Library_Unit
(Cunit
(Main_Unit
)));
1271 U
:= Parent_Spec
(Main_Spec
);
1272 while Present
(U
) loop
1273 if U
= Parent
(Decl
) then
1274 Generate_Reference
(Id
, Scope
(Id
), 'k', False);
1277 elsif Nkind
(Unit
(U
)) = N_Package_Body
then
1281 U
:= Parent_Spec
(Unit
(U
));
1286 end Generate_Parent_References
;
1288 ---------------------
1289 -- Is_Public_Child --
1290 ---------------------
1292 function Is_Public_Child
(Child
, Unit
: Entity_Id
) return Boolean is
1294 if not Is_Private_Descendant
(Child
) then
1297 if Child
= Unit
then
1298 return not Private_Present
(
1299 Parent
(Unit_Declaration_Node
(Child
)));
1301 return Is_Public_Child
(Scope
(Child
), Unit
);
1304 end Is_Public_Child
;
1306 ----------------------------------------
1307 -- Inspect_Unchecked_Union_Completion --
1308 ----------------------------------------
1310 procedure Inspect_Unchecked_Union_Completion
(Decls
: List_Id
) is
1314 Decl
:= First
(Decls
);
1315 while Present
(Decl
) loop
1317 -- We are looking at an incomplete or private type declaration
1318 -- with a known_discriminant_part whose full view is an
1321 if Nkind_In
(Decl
, N_Incomplete_Type_Declaration
,
1322 N_Private_Type_Declaration
)
1323 and then Has_Discriminants
(Defining_Identifier
(Decl
))
1324 and then Present
(Full_View
(Defining_Identifier
(Decl
)))
1326 Is_Unchecked_Union
(Full_View
(Defining_Identifier
(Decl
)))
1329 ("completion of discriminated partial view "
1330 & "cannot be an unchecked union",
1331 Full_View
(Defining_Identifier
(Decl
)));
1336 end Inspect_Unchecked_Union_Completion
;
1338 -----------------------------------------
1339 -- Install_Parent_Private_Declarations --
1340 -----------------------------------------
1342 procedure Install_Parent_Private_Declarations
(Inst_Id
: Entity_Id
) is
1343 Inst_Par
: Entity_Id
;
1344 Gen_Par
: Entity_Id
;
1345 Inst_Node
: Node_Id
;
1348 Inst_Par
:= Inst_Id
;
1351 Generic_Parent
(Specification
(Unit_Declaration_Node
(Inst_Par
)));
1352 while Present
(Gen_Par
) and then Is_Child_Unit
(Gen_Par
) loop
1353 Inst_Node
:= Get_Package_Instantiation_Node
(Inst_Par
);
1355 if Nkind_In
(Inst_Node
, N_Package_Instantiation
,
1356 N_Formal_Package_Declaration
)
1357 and then Nkind
(Name
(Inst_Node
)) = N_Expanded_Name
1359 Inst_Par
:= Entity
(Prefix
(Name
(Inst_Node
)));
1361 if Present
(Renamed_Entity
(Inst_Par
)) then
1362 Inst_Par
:= Renamed_Entity
(Inst_Par
);
1367 (Specification
(Unit_Declaration_Node
(Inst_Par
)));
1369 -- Install the private declarations and private use clauses
1370 -- of a parent instance of the child instance, unless the
1371 -- parent instance private declarations have already been
1372 -- installed earlier in Analyze_Package_Specification, which
1373 -- happens when a generic child is instantiated, and the
1374 -- instance is a child of the parent instance.
1376 -- Installing the use clauses of the parent instance twice
1377 -- is both unnecessary and wrong, because it would cause the
1378 -- clauses to be chained to themselves in the use clauses
1379 -- list of the scope stack entry. That in turn would cause
1380 -- an endless loop from End_Use_Clauses upon scope exit.
1382 -- The parent is now fully visible. It may be a hidden open
1383 -- scope if we are currently compiling some child instance
1384 -- declared within it, but while the current instance is being
1385 -- compiled the parent is immediately visible. In particular
1386 -- its entities must remain visible if a stack save/restore
1387 -- takes place through a call to Rtsfind.
1389 if Present
(Gen_Par
) then
1390 if not In_Private_Part
(Inst_Par
) then
1391 Install_Private_Declarations
(Inst_Par
);
1392 Set_Use
(Private_Declarations
1394 (Unit_Declaration_Node
(Inst_Par
))));
1395 Set_Is_Hidden_Open_Scope
(Inst_Par
, False);
1398 -- If we've reached the end of the generic instance parents,
1399 -- then finish off by looping through the nongeneric parents
1400 -- and installing their private declarations.
1402 -- If one of the non-generic parents is itself on the scope
1403 -- stack, do not install its private declarations: they are
1404 -- installed in due time when the private part of that parent
1405 -- is analyzed. This is delicate ???
1408 while Present
(Inst_Par
)
1409 and then Inst_Par
/= Standard_Standard
1410 and then (not In_Open_Scopes
(Inst_Par
)
1411 or else not In_Private_Part
(Inst_Par
))
1413 Install_Private_Declarations
(Inst_Par
);
1414 Set_Use
(Private_Declarations
1416 (Unit_Declaration_Node
(Inst_Par
))));
1417 Inst_Par
:= Scope
(Inst_Par
);
1427 end Install_Parent_Private_Declarations
;
1429 -- Start of processing for Analyze_Package_Specification
1432 if Present
(Vis_Decls
) then
1433 Analyze_Declarations
(Vis_Decls
);
1436 -- Inspect the entities defined in the package and ensure that all
1437 -- incomplete types have received full declarations. Build default
1438 -- initial condition and invariant procedures for all qualifying types.
1440 E
:= First_Entity
(Id
);
1441 while Present
(E
) loop
1443 -- Check on incomplete types
1445 -- AI05-0213: A formal incomplete type has no completion
1447 if Ekind
(E
) = E_Incomplete_Type
1448 and then No
(Full_View
(E
))
1449 and then not Is_Generic_Type
(E
)
1451 Error_Msg_N
("no declaration in visible part for incomplete}", E
);
1456 -- Each private type subject to pragma Default_Initial_Condition
1457 -- declares a specialized procedure which verifies the assumption
1458 -- of the pragma. The declaration appears in the visible part of
1459 -- the package to allow for being called from the outside.
1461 if Has_Default_Init_Cond
(E
) then
1462 Build_Default_Init_Cond_Procedure_Declaration
(E
);
1464 -- A private extension inherits the default initial condition
1465 -- procedure from its parent type.
1467 elsif Has_Inherited_Default_Init_Cond
(E
) then
1468 Inherit_Default_Init_Cond_Procedure
(E
);
1471 -- If invariants are present, build the invariant procedure for a
1472 -- private type, but not any of its subtypes.
1474 if Has_Invariants
(E
) then
1475 if Ekind
(E
) = E_Private_Subtype
then
1478 Build_Invariant_Procedure
(E
, N
);
1486 if Is_Remote_Call_Interface
(Id
)
1487 and then Nkind
(Parent
(Parent
(N
))) = N_Compilation_Unit
1489 Validate_RCI_Declarations
(Id
);
1492 -- Save global references in the visible declarations, before installing
1493 -- private declarations of parent unit if there is one, because the
1494 -- privacy status of types defined in the parent will change. This is
1495 -- only relevant for generic child units, but is done in all cases for
1498 if Ekind
(Id
) = E_Generic_Package
1499 and then Nkind
(Orig_Decl
) = N_Generic_Package_Declaration
1502 Orig_Spec
: constant Node_Id
:= Specification
(Orig_Decl
);
1503 Save_Priv
: constant List_Id
:= Private_Declarations
(Orig_Spec
);
1505 Set_Private_Declarations
(Orig_Spec
, Empty_List
);
1506 Save_Global_References
(Orig_Decl
);
1507 Set_Private_Declarations
(Orig_Spec
, Save_Priv
);
1511 -- If package is a public child unit, then make the private declarations
1512 -- of the parent visible.
1514 Public_Child
:= False;
1518 Pack_Decl
: Node_Id
;
1523 Par_Spec
:= Parent_Spec
(Parent
(N
));
1525 -- If the package is formal package of an enclosing generic, it is
1526 -- transformed into a local generic declaration, and compiled to make
1527 -- its spec available. We need to retrieve the original generic to
1528 -- determine whether it is a child unit, and install its parents.
1532 Nkind
(Original_Node
(Parent
(N
))) = N_Formal_Package_Declaration
1534 Par
:= Entity
(Name
(Original_Node
(Parent
(N
))));
1535 Par_Spec
:= Parent_Spec
(Unit_Declaration_Node
(Par
));
1538 if Present
(Par_Spec
) then
1539 Generate_Parent_References
;
1541 while Scope
(Par
) /= Standard_Standard
1542 and then Is_Public_Child
(Id
, Par
)
1543 and then In_Open_Scopes
(Par
)
1545 Public_Child
:= True;
1547 Install_Private_Declarations
(Par
);
1548 Install_Private_With_Clauses
(Par
);
1549 Pack_Decl
:= Unit_Declaration_Node
(Par
);
1550 Set_Use
(Private_Declarations
(Specification
(Pack_Decl
)));
1555 if Is_Compilation_Unit
(Id
) then
1556 Install_Private_With_Clauses
(Id
);
1559 -- The current compilation unit may include private with_clauses,
1560 -- which are visible in the private part of the current nested
1561 -- package, and have to be installed now. This is not done for
1562 -- nested instantiations, where the private with_clauses of the
1563 -- enclosing unit have no effect once the instantiation info is
1564 -- established and we start analyzing the package declaration.
1567 Comp_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
1569 if Is_Package_Or_Generic_Package
(Comp_Unit
)
1570 and then not In_Private_Part
(Comp_Unit
)
1571 and then not In_Instance
1573 Install_Private_With_Clauses
(Comp_Unit
);
1574 Private_With_Clauses_Installed
:= True;
1579 -- If this is a package associated with a generic instance or formal
1580 -- package, then the private declarations of each of the generic's
1581 -- parents must be installed at this point.
1583 if Is_Generic_Instance
(Id
) then
1584 Install_Parent_Private_Declarations
(Id
);
1587 -- Analyze private part if present. The flag In_Private_Part is reset
1588 -- in End_Package_Scope.
1590 L
:= Last_Entity
(Id
);
1592 if Present
(Priv_Decls
) then
1593 Set_In_Private_Part
(Id
);
1595 -- Upon entering a public child's private part, it may be necessary
1596 -- to declare subprograms that were derived in the package's visible
1597 -- part but not yet made visible.
1599 if Public_Child
then
1600 Declare_Inherited_Private_Subprograms
(Id
);
1603 Analyze_Declarations
(Priv_Decls
);
1605 -- Check the private declarations for incomplete deferred constants
1607 Inspect_Deferred_Constant_Completion
(Priv_Decls
);
1609 -- The first private entity is the immediate follower of the last
1610 -- visible entity, if there was one.
1613 Set_First_Private_Entity
(Id
, Next_Entity
(L
));
1615 Set_First_Private_Entity
(Id
, First_Entity
(Id
));
1618 -- There may be inherited private subprograms that need to be declared,
1619 -- even in the absence of an explicit private part. If there are any
1620 -- public declarations in the package and the package is a public child
1621 -- unit, then an implicit private part is assumed.
1623 elsif Present
(L
) and then Public_Child
then
1624 Set_In_Private_Part
(Id
);
1625 Declare_Inherited_Private_Subprograms
(Id
);
1626 Set_First_Private_Entity
(Id
, Next_Entity
(L
));
1629 E
:= First_Entity
(Id
);
1630 while Present
(E
) loop
1632 -- Check rule of 3.6(11), which in general requires waiting till all
1633 -- full types have been seen.
1635 if Ekind
(E
) = E_Record_Type
or else Ekind
(E
) = E_Array_Type
then
1636 Check_Aliased_Component_Types
(E
);
1639 -- Check preelaborable initialization for full type completing a
1640 -- private type for which pragma Preelaborable_Initialization given.
1643 and then Must_Have_Preelab_Init
(E
)
1644 and then not Has_Preelaborable_Initialization
(E
)
1647 ("full view of & does not have preelaborable initialization", E
);
1650 -- An invariant may appear on a full view of a type
1653 and then Has_Private_Declaration
(E
)
1654 and then Nkind
(Parent
(E
)) = N_Full_Type_Declaration
1655 and then Has_Aspects
(Parent
(E
))
1661 ASN
:= First
(Aspect_Specifications
(Parent
(E
)));
1662 while Present
(ASN
) loop
1663 if Nam_In
(Chars
(Identifier
(ASN
)), Name_Invariant
,
1664 Name_Type_Invariant
)
1666 Build_Invariant_Procedure
(E
, N
);
1678 -- Ada 2005 (AI-216): The completion of an incomplete or private type
1679 -- declaration having a known_discriminant_part shall not be an
1680 -- unchecked union type.
1682 if Present
(Vis_Decls
) then
1683 Inspect_Unchecked_Union_Completion
(Vis_Decls
);
1686 if Present
(Priv_Decls
) then
1687 Inspect_Unchecked_Union_Completion
(Priv_Decls
);
1690 if Ekind
(Id
) = E_Generic_Package
1691 and then Nkind
(Orig_Decl
) = N_Generic_Package_Declaration
1692 and then Present
(Priv_Decls
)
1694 -- Save global references in private declarations, ignoring the
1695 -- visible declarations that were processed earlier.
1698 Orig_Spec
: constant Node_Id
:= Specification
(Orig_Decl
);
1699 Save_Vis
: constant List_Id
:= Visible_Declarations
(Orig_Spec
);
1700 Save_Form
: constant List_Id
:=
1701 Generic_Formal_Declarations
(Orig_Decl
);
1704 Set_Visible_Declarations
(Orig_Spec
, Empty_List
);
1705 Set_Generic_Formal_Declarations
(Orig_Decl
, Empty_List
);
1706 Save_Global_References
(Orig_Decl
);
1707 Set_Generic_Formal_Declarations
(Orig_Decl
, Save_Form
);
1708 Set_Visible_Declarations
(Orig_Spec
, Save_Vis
);
1712 Process_End_Label
(N
, 'e', Id
);
1714 -- Remove private_with_clauses of enclosing compilation unit, if they
1717 if Private_With_Clauses_Installed
then
1718 Remove_Private_With_Clauses
(Cunit
(Current_Sem_Unit
));
1721 -- For the case of a library level package, we must go through all the
1722 -- entities clearing the indications that the value may be constant and
1723 -- not modified. Why? Because any client of this package may modify
1724 -- these values freely from anywhere. This also applies to any nested
1725 -- packages or generic packages.
1727 -- For now we unconditionally clear constants for packages that are
1728 -- instances of generic packages. The reason is that we do not have the
1729 -- body yet, and we otherwise think things are unreferenced when they
1730 -- are not. This should be fixed sometime (the effect is not terrible,
1731 -- we just lose some warnings, and also some cases of value propagation)
1734 if Is_Library_Level_Entity
(Id
)
1735 or else Is_Generic_Instance
(Id
)
1737 Clear_Constants
(Id
, First_Entity
(Id
));
1738 Clear_Constants
(Id
, First_Private_Entity
(Id
));
1741 -- Issue an error in SPARK mode if a package specification contains
1742 -- more than one tagged type or type extension.
1744 Check_One_Tagged_Type_Or_Extension_At_Most
;
1746 -- If switch set, output information on why body required
1748 if List_Body_Required_Info
1749 and then In_Extended_Main_Source_Unit
(Id
)
1750 and then Unit_Requires_Body
(Id
)
1752 Unit_Requires_Body_Info
(Id
);
1754 end Analyze_Package_Specification
;
1756 --------------------------------------
1757 -- Analyze_Private_Type_Declaration --
1758 --------------------------------------
1760 procedure Analyze_Private_Type_Declaration
(N
: Node_Id
) is
1761 PF
: constant Boolean := Is_Pure
(Enclosing_Lib_Unit_Entity
);
1762 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1765 Generate_Definition
(Id
);
1766 Set_Is_Pure
(Id
, PF
);
1767 Init_Size_Align
(Id
);
1769 if not Is_Package_Or_Generic_Package
(Current_Scope
)
1770 or else In_Private_Part
(Current_Scope
)
1772 Error_Msg_N
("invalid context for private declaration", N
);
1775 New_Private_Type
(N
, Id
, N
);
1776 Set_Depends_On_Private
(Id
);
1778 -- A type declared within a Ghost scope is automatically Ghost
1779 -- (SPARK RM 6.9(2)).
1781 if Within_Ghost_Scope
then
1782 Set_Is_Ghost_Entity
(Id
);
1785 if Has_Aspects
(N
) then
1786 Analyze_Aspect_Specifications
(N
, Id
);
1788 end Analyze_Private_Type_Declaration
;
1790 ----------------------------------
1791 -- Check_Anonymous_Access_Types --
1792 ----------------------------------
1794 procedure Check_Anonymous_Access_Types
1795 (Spec_Id
: Entity_Id
;
1802 -- Itype references are only needed by gigi, to force elaboration of
1803 -- itypes. In the absence of code generation, they are not needed.
1805 if not Expander_Active
then
1809 E
:= First_Entity
(Spec_Id
);
1810 while Present
(E
) loop
1811 if Ekind
(E
) = E_Anonymous_Access_Type
1812 and then From_Limited_With
(E
)
1814 IR
:= Make_Itype_Reference
(Sloc
(P_Body
));
1817 if No
(Declarations
(P_Body
)) then
1818 Set_Declarations
(P_Body
, New_List
(IR
));
1820 Prepend
(IR
, Declarations
(P_Body
));
1826 end Check_Anonymous_Access_Types
;
1828 -------------------------------------------
1829 -- Declare_Inherited_Private_Subprograms --
1830 -------------------------------------------
1832 procedure Declare_Inherited_Private_Subprograms
(Id
: Entity_Id
) is
1834 function Is_Primitive_Of
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
1835 -- Check whether an inherited subprogram S is an operation of an
1836 -- untagged derived type T.
1838 ---------------------
1839 -- Is_Primitive_Of --
1840 ---------------------
1842 function Is_Primitive_Of
(T
: Entity_Id
; S
: Entity_Id
) return Boolean is
1846 -- If the full view is a scalar type, the type is the anonymous base
1847 -- type, but the operation mentions the first subtype, so check the
1848 -- signature against the base type.
1850 if Base_Type
(Etype
(S
)) = Base_Type
(T
) then
1854 Formal
:= First_Formal
(S
);
1855 while Present
(Formal
) loop
1856 if Base_Type
(Etype
(Formal
)) = Base_Type
(T
) then
1860 Next_Formal
(Formal
);
1865 end Is_Primitive_Of
;
1872 Op_Elmt_2
: Elmt_Id
;
1873 Prim_Op
: Entity_Id
;
1874 New_Op
: Entity_Id
:= Empty
;
1875 Parent_Subp
: Entity_Id
;
1878 -- Start of processing for Declare_Inherited_Private_Subprograms
1881 E
:= First_Entity
(Id
);
1882 while Present
(E
) loop
1884 -- If the entity is a nonprivate type extension whose parent type
1885 -- is declared in an open scope, then the type may have inherited
1886 -- operations that now need to be made visible. Ditto if the entity
1887 -- is a formal derived type in a child unit.
1889 if ((Is_Derived_Type
(E
) and then not Is_Private_Type
(E
))
1891 (Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
1892 and then Is_Generic_Type
(E
)))
1893 and then In_Open_Scopes
(Scope
(Etype
(E
)))
1894 and then Is_Base_Type
(E
)
1896 if Is_Tagged_Type
(E
) then
1897 Op_List
:= Primitive_Operations
(E
);
1899 Tag
:= First_Tag_Component
(E
);
1901 Op_Elmt
:= First_Elmt
(Op_List
);
1902 while Present
(Op_Elmt
) loop
1903 Prim_Op
:= Node
(Op_Elmt
);
1905 -- Search primitives that are implicit operations with an
1906 -- internal name whose parent operation has a normal name.
1908 if Present
(Alias
(Prim_Op
))
1909 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= E
1910 and then not Comes_From_Source
(Prim_Op
)
1911 and then Is_Internal_Name
(Chars
(Prim_Op
))
1912 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
1914 Parent_Subp
:= Alias
(Prim_Op
);
1916 -- Case 1: Check if the type has also an explicit
1917 -- overriding for this primitive.
1919 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
1920 while Present
(Op_Elmt_2
) loop
1922 -- Skip entities with attribute Interface_Alias since
1923 -- they are not overriding primitives (these entities
1924 -- link an interface primitive with their covering
1927 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
1928 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
1929 and then No
(Interface_Alias
(Node
(Op_Elmt_2
)))
1931 -- The private inherited operation has been
1932 -- overridden by an explicit subprogram:
1933 -- replace the former by the latter.
1935 New_Op
:= Node
(Op_Elmt_2
);
1936 Replace_Elmt
(Op_Elmt
, New_Op
);
1937 Remove_Elmt
(Op_List
, Op_Elmt_2
);
1938 Set_Overridden_Operation
(New_Op
, Parent_Subp
);
1940 -- We don't need to inherit its dispatching slot.
1941 -- Set_All_DT_Position has previously ensured that
1942 -- the same slot was assigned to the two primitives
1945 and then Present
(DTC_Entity
(New_Op
))
1946 and then Present
(DTC_Entity
(Prim_Op
))
1949 (DT_Position
(New_Op
) = DT_Position
(Prim_Op
));
1953 goto Next_Primitive
;
1956 Next_Elmt
(Op_Elmt_2
);
1959 -- Case 2: We have not found any explicit overriding and
1960 -- hence we need to declare the operation (i.e., make it
1963 Derive_Subprogram
(New_Op
, Alias
(Prim_Op
), E
, Etype
(E
));
1965 -- Inherit the dispatching slot if E is already frozen
1968 and then Present
(DTC_Entity
(Alias
(Prim_Op
)))
1970 Set_DTC_Entity_Value
(E
, New_Op
);
1971 Set_DT_Position
(New_Op
,
1972 DT_Position
(Alias
(Prim_Op
)));
1976 (Is_Dispatching_Operation
(New_Op
)
1977 and then Node
(Last_Elmt
(Op_List
)) = New_Op
);
1979 -- Substitute the new operation for the old one in the
1980 -- type's primitive operations list. Since the new
1981 -- operation was also just added to the end of list,
1982 -- the last element must be removed.
1984 -- (Question: is there a simpler way of declaring the
1985 -- operation, say by just replacing the name of the
1986 -- earlier operation, reentering it in the in the symbol
1987 -- table (how?), and marking it as private???)
1989 Replace_Elmt
(Op_Elmt
, New_Op
);
1990 Remove_Last_Elmt
(Op_List
);
1994 Next_Elmt
(Op_Elmt
);
1997 -- Generate listing showing the contents of the dispatch table
1999 if Debug_Flag_ZZ
then
2004 -- For untagged type, scan forward to locate inherited hidden
2007 Prim_Op
:= Next_Entity
(E
);
2008 while Present
(Prim_Op
) loop
2009 if Is_Subprogram
(Prim_Op
)
2010 and then Present
(Alias
(Prim_Op
))
2011 and then not Comes_From_Source
(Prim_Op
)
2012 and then Is_Internal_Name
(Chars
(Prim_Op
))
2013 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
2014 and then Is_Primitive_Of
(E
, Prim_Op
)
2016 Derive_Subprogram
(New_Op
, Alias
(Prim_Op
), E
, Etype
(E
));
2019 Next_Entity
(Prim_Op
);
2021 -- Derived operations appear immediately after the type
2022 -- declaration (or the following subtype indication for
2023 -- a derived scalar type). Further declarations cannot
2024 -- include inherited operations of the type.
2026 if Present
(Prim_Op
) then
2027 exit when Ekind
(Prim_Op
) not in Overloadable_Kind
;
2035 end Declare_Inherited_Private_Subprograms
;
2037 -----------------------
2038 -- End_Package_Scope --
2039 -----------------------
2041 procedure End_Package_Scope
(P
: Entity_Id
) is
2043 Uninstall_Declarations
(P
);
2045 end End_Package_Scope
;
2047 ---------------------------
2048 -- Exchange_Declarations --
2049 ---------------------------
2051 procedure Exchange_Declarations
(Id
: Entity_Id
) is
2052 Full_Id
: constant Entity_Id
:= Full_View
(Id
);
2053 H1
: constant Entity_Id
:= Homonym
(Id
);
2054 Next1
: constant Entity_Id
:= Next_Entity
(Id
);
2059 -- If missing full declaration for type, nothing to exchange
2061 if No
(Full_Id
) then
2065 -- Otherwise complete the exchange, and preserve semantic links
2067 Next2
:= Next_Entity
(Full_Id
);
2068 H2
:= Homonym
(Full_Id
);
2070 -- Reset full declaration pointer to reflect the switched entities and
2071 -- readjust the next entity chains.
2073 Exchange_Entities
(Id
, Full_Id
);
2075 Set_Next_Entity
(Id
, Next1
);
2076 Set_Homonym
(Id
, H1
);
2078 Set_Full_View
(Full_Id
, Id
);
2079 Set_Next_Entity
(Full_Id
, Next2
);
2080 Set_Homonym
(Full_Id
, H2
);
2081 end Exchange_Declarations
;
2083 ----------------------------
2084 -- Install_Package_Entity --
2085 ----------------------------
2087 procedure Install_Package_Entity
(Id
: Entity_Id
) is
2089 if not Is_Internal
(Id
) then
2090 if Debug_Flag_E
then
2091 Write_Str
("Install: ");
2092 Write_Name
(Chars
(Id
));
2096 if Is_Child_Unit
(Id
) then
2099 -- Do not enter implicitly inherited non-overridden subprograms of
2100 -- a tagged type back into visibility if they have non-conformant
2101 -- homographs (Ada RM 8.3 12.3/2).
2103 elsif Is_Hidden_Non_Overridden_Subpgm
(Id
) then
2107 Set_Is_Immediately_Visible
(Id
);
2110 end Install_Package_Entity
;
2112 ----------------------------------
2113 -- Install_Private_Declarations --
2114 ----------------------------------
2116 procedure Install_Private_Declarations
(P
: Entity_Id
) is
2119 Priv_Deps
: Elist_Id
;
2121 procedure Swap_Private_Dependents
(Priv_Deps
: Elist_Id
);
2122 -- When the full view of a private type is made available, we do the
2123 -- same for its private dependents under proper visibility conditions.
2124 -- When compiling a grand-chid unit this needs to be done recursively.
2126 -----------------------------
2127 -- Swap_Private_Dependents --
2128 -----------------------------
2130 procedure Swap_Private_Dependents
(Priv_Deps
: Elist_Id
) is
2133 Priv_Elmt
: Elmt_Id
;
2137 Priv_Elmt
:= First_Elmt
(Priv_Deps
);
2138 while Present
(Priv_Elmt
) loop
2139 Priv
:= Node
(Priv_Elmt
);
2141 -- Before the exchange, verify that the presence of the Full_View
2142 -- field. This field will be empty if the entity has already been
2143 -- installed due to a previous call.
2145 if Present
(Full_View
(Priv
)) and then Is_Visible_Dependent
(Priv
)
2147 if Is_Private_Type
(Priv
) then
2148 Deps
:= Private_Dependents
(Priv
);
2154 -- For each subtype that is swapped, we also swap the reference
2155 -- to it in Private_Dependents, to allow access to it when we
2156 -- swap them out in End_Package_Scope.
2158 Replace_Elmt
(Priv_Elmt
, Full_View
(Priv
));
2159 Exchange_Declarations
(Priv
);
2160 Set_Is_Immediately_Visible
2161 (Priv
, In_Open_Scopes
(Scope
(Priv
)));
2162 Set_Is_Potentially_Use_Visible
2163 (Priv
, Is_Potentially_Use_Visible
(Node
(Priv_Elmt
)));
2165 -- Within a child unit, recurse, except in generic child unit,
2166 -- which (unfortunately) handle private_dependents separately.
2169 and then Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
2170 and then not Is_Empty_Elmt_List
(Deps
)
2171 and then not Inside_A_Generic
2173 Swap_Private_Dependents
(Deps
);
2177 Next_Elmt
(Priv_Elmt
);
2179 end Swap_Private_Dependents
;
2181 -- Start of processing for Install_Private_Declarations
2184 -- First exchange declarations for private types, so that the full
2185 -- declaration is visible. For each private type, we check its
2186 -- Private_Dependents list and also exchange any subtypes of or derived
2187 -- types from it. Finally, if this is a Taft amendment type, the
2188 -- incomplete declaration is irrelevant, and we want to link the
2189 -- eventual full declaration with the original private one so we
2190 -- also skip the exchange.
2192 Id
:= First_Entity
(P
);
2193 while Present
(Id
) and then Id
/= First_Private_Entity
(P
) loop
2194 if Is_Private_Base_Type
(Id
)
2195 and then Present
(Full_View
(Id
))
2196 and then Comes_From_Source
(Full_View
(Id
))
2197 and then Scope
(Full_View
(Id
)) = Scope
(Id
)
2198 and then Ekind
(Full_View
(Id
)) /= E_Incomplete_Type
2200 -- If there is a use-type clause on the private type, set the full
2201 -- view accordingly.
2203 Set_In_Use
(Full_View
(Id
), In_Use
(Id
));
2204 Full
:= Full_View
(Id
);
2206 if Is_Private_Base_Type
(Full
)
2207 and then Has_Private_Declaration
(Full
)
2208 and then Nkind
(Parent
(Full
)) = N_Full_Type_Declaration
2209 and then In_Open_Scopes
(Scope
(Etype
(Full
)))
2210 and then In_Package_Body
(Current_Scope
)
2211 and then not Is_Private_Type
(Etype
(Full
))
2213 -- This is the completion of a private type by a derivation
2214 -- from another private type which is not private anymore. This
2215 -- can only happen in a package nested within a child package,
2216 -- when the parent type is defined in the parent unit. At this
2217 -- point the current type is not private either, and we have
2218 -- to install the underlying full view, which is now visible.
2219 -- Save the current full view as well, so that all views can be
2220 -- restored on exit. It may seem that after compiling the child
2221 -- body there are not environments to restore, but the back-end
2222 -- expects those links to be valid, and freeze nodes depend on
2225 if No
(Full_View
(Full
))
2226 and then Present
(Underlying_Full_View
(Full
))
2228 Set_Full_View
(Id
, Underlying_Full_View
(Full
));
2229 Set_Underlying_Full_View
(Id
, Full
);
2231 Set_Underlying_Full_View
(Full
, Empty
);
2232 Set_Is_Frozen
(Full_View
(Id
));
2236 Priv_Deps
:= Private_Dependents
(Id
);
2237 Exchange_Declarations
(Id
);
2238 Set_Is_Immediately_Visible
(Id
);
2239 Swap_Private_Dependents
(Priv_Deps
);
2245 -- Next make other declarations in the private part visible as well
2247 Id
:= First_Private_Entity
(P
);
2248 while Present
(Id
) loop
2249 Install_Package_Entity
(Id
);
2250 Set_Is_Hidden
(Id
, False);
2254 -- Indicate that the private part is currently visible, so it can be
2255 -- properly reset on exit.
2257 Set_In_Private_Part
(P
);
2258 end Install_Private_Declarations
;
2260 ----------------------------------
2261 -- Install_Visible_Declarations --
2262 ----------------------------------
2264 procedure Install_Visible_Declarations
(P
: Entity_Id
) is
2266 Last_Entity
: Entity_Id
;
2270 (Is_Package_Or_Generic_Package
(P
) or else Is_Record_Type
(P
));
2272 if Is_Package_Or_Generic_Package
(P
) then
2273 Last_Entity
:= First_Private_Entity
(P
);
2275 Last_Entity
:= Empty
;
2278 Id
:= First_Entity
(P
);
2279 while Present
(Id
) and then Id
/= Last_Entity
loop
2280 Install_Package_Entity
(Id
);
2283 end Install_Visible_Declarations
;
2285 --------------------------
2286 -- Is_Private_Base_Type --
2287 --------------------------
2289 function Is_Private_Base_Type
(E
: Entity_Id
) return Boolean is
2291 return Ekind
(E
) = E_Private_Type
2292 or else Ekind
(E
) = E_Limited_Private_Type
2293 or else Ekind
(E
) = E_Record_Type_With_Private
;
2294 end Is_Private_Base_Type
;
2296 --------------------------
2297 -- Is_Visible_Dependent --
2298 --------------------------
2300 function Is_Visible_Dependent
(Dep
: Entity_Id
) return Boolean
2302 S
: constant Entity_Id
:= Scope
(Dep
);
2305 -- Renamings created for actual types have the visibility of the actual
2307 if Ekind
(S
) = E_Package
2308 and then Is_Generic_Instance
(S
)
2309 and then (Is_Generic_Actual_Type
(Dep
)
2310 or else Is_Generic_Actual_Type
(Full_View
(Dep
)))
2314 elsif not (Is_Derived_Type
(Dep
))
2315 and then Is_Derived_Type
(Full_View
(Dep
))
2317 -- When instantiating a package body, the scope stack is empty, so
2318 -- check instead whether the dependent type is defined in the same
2319 -- scope as the instance itself.
2321 return In_Open_Scopes
(S
)
2322 or else (Is_Generic_Instance
(Current_Scope
)
2323 and then Scope
(Dep
) = Scope
(Current_Scope
));
2327 end Is_Visible_Dependent
;
2329 ----------------------------
2330 -- May_Need_Implicit_Body --
2331 ----------------------------
2333 procedure May_Need_Implicit_Body
(E
: Entity_Id
) is
2334 P
: constant Node_Id
:= Unit_Declaration_Node
(E
);
2335 S
: constant Node_Id
:= Parent
(P
);
2340 if not Has_Completion
(E
)
2341 and then Nkind
(P
) = N_Package_Declaration
2342 and then (Present
(Activation_Chain_Entity
(P
)) or else Has_RACW
(E
))
2345 Make_Package_Body
(Sloc
(E
),
2346 Defining_Unit_Name
=> Make_Defining_Identifier
(Sloc
(E
),
2347 Chars
=> Chars
(E
)),
2348 Declarations
=> New_List
);
2350 if Nkind
(S
) = N_Package_Specification
then
2351 if Present
(Private_Declarations
(S
)) then
2352 Decls
:= Private_Declarations
(S
);
2354 Decls
:= Visible_Declarations
(S
);
2357 Decls
:= Declarations
(S
);
2363 end May_Need_Implicit_Body
;
2365 ----------------------
2366 -- New_Private_Type --
2367 ----------------------
2369 procedure New_Private_Type
(N
: Node_Id
; Id
: Entity_Id
; Def
: Node_Id
) is
2371 -- For other than Ada 2012, enter the name in the current scope
2373 if Ada_Version
< Ada_2012
then
2376 -- Ada 2012 (AI05-0162): Enter the name in the current scope. Note that
2377 -- there may be an incomplete previous view.
2383 Prev
:= Find_Type_Name
(N
);
2384 pragma Assert
(Prev
= Id
2385 or else (Ekind
(Prev
) = E_Incomplete_Type
2386 and then Present
(Full_View
(Prev
))
2387 and then Full_View
(Prev
) = Id
));
2391 if Limited_Present
(Def
) then
2392 Set_Ekind
(Id
, E_Limited_Private_Type
);
2394 Set_Ekind
(Id
, E_Private_Type
);
2398 Set_Has_Delayed_Freeze
(Id
);
2399 Set_Is_First_Subtype
(Id
);
2400 Init_Size_Align
(Id
);
2402 Set_Is_Constrained
(Id
,
2403 No
(Discriminant_Specifications
(N
))
2404 and then not Unknown_Discriminants_Present
(N
));
2406 -- Set tagged flag before processing discriminants, to catch illegal
2409 Set_Is_Tagged_Type
(Id
, Tagged_Present
(Def
));
2411 Set_Discriminant_Constraint
(Id
, No_Elist
);
2412 Set_Stored_Constraint
(Id
, No_Elist
);
2414 if Present
(Discriminant_Specifications
(N
)) then
2416 Process_Discriminants
(N
);
2419 elsif Unknown_Discriminants_Present
(N
) then
2420 Set_Has_Unknown_Discriminants
(Id
);
2423 Set_Private_Dependents
(Id
, New_Elmt_List
);
2425 if Tagged_Present
(Def
) then
2426 Set_Ekind
(Id
, E_Record_Type_With_Private
);
2427 Set_Direct_Primitive_Operations
(Id
, New_Elmt_List
);
2428 Set_Is_Abstract_Type
(Id
, Abstract_Present
(Def
));
2429 Set_Is_Limited_Record
(Id
, Limited_Present
(Def
));
2430 Set_Has_Delayed_Freeze
(Id
, True);
2432 -- Create a class-wide type with the same attributes
2434 Make_Class_Wide_Type
(Id
);
2436 elsif Abstract_Present
(Def
) then
2437 Error_Msg_N
("only a tagged type can be abstract", N
);
2439 end New_Private_Type
;
2441 ---------------------------------
2442 -- Requires_Completion_In_Body --
2443 ---------------------------------
2445 function Requires_Completion_In_Body
2447 Pack_Id
: Entity_Id
) return Boolean is
2449 -- Always ignore child units. Child units get added to the entity list
2450 -- of a parent unit, but are not original entities of the parent, and
2451 -- so do not affect whether the parent needs a body.
2453 if Is_Child_Unit
(Id
) then
2456 -- Ignore formal packages and their renamings
2458 elsif Ekind
(Id
) = E_Package
2459 and then Nkind
(Original_Node
(Unit_Declaration_Node
(Id
))) =
2460 N_Formal_Package_Declaration
2464 -- A Ghost entity declared in a non-Ghost package does not force the
2465 -- need for a body (SPARK RM 6.9(11)).
2467 elsif not Is_Ghost_Entity
(Pack_Id
) and then Is_Ghost_Entity
(Id
) then
2470 -- Otherwise test to see if entity requires a completion. Note that
2471 -- subprogram entities whose declaration does not come from source are
2472 -- ignored here on the basis that we assume the expander will provide an
2473 -- implicit completion at some point.
2475 elsif (Is_Overloadable
(Id
)
2476 and then Ekind
(Id
) /= E_Enumeration_Literal
2477 and then Ekind
(Id
) /= E_Operator
2478 and then not Is_Abstract_Subprogram
(Id
)
2479 and then not Has_Completion
(Id
)
2480 and then Comes_From_Source
(Parent
(Id
)))
2483 (Ekind
(Id
) = E_Package
2484 and then Id
/= Pack_Id
2485 and then not Has_Completion
(Id
)
2486 and then Unit_Requires_Body
(Id
))
2489 (Ekind
(Id
) = E_Incomplete_Type
2490 and then No
(Full_View
(Id
))
2491 and then not Is_Generic_Type
(Id
))
2494 (Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
)
2495 and then not Has_Completion
(Id
))
2498 (Ekind
(Id
) = E_Generic_Package
2499 and then Id
/= Pack_Id
2500 and then not Has_Completion
(Id
)
2501 and then Unit_Requires_Body
(Id
))
2504 (Is_Generic_Subprogram
(Id
)
2505 and then not Has_Completion
(Id
))
2510 -- Otherwise the entity does not require completion in a package body
2515 end Requires_Completion_In_Body
;
2517 ----------------------------
2518 -- Uninstall_Declarations --
2519 ----------------------------
2521 procedure Uninstall_Declarations
(P
: Entity_Id
) is
2522 Decl
: constant Node_Id
:= Unit_Declaration_Node
(P
);
2525 Priv_Elmt
: Elmt_Id
;
2526 Priv_Sub
: Entity_Id
;
2528 procedure Preserve_Full_Attributes
(Priv
, Full
: Entity_Id
);
2529 -- Copy to the private declaration the attributes of the full view that
2530 -- need to be available for the partial view also.
2532 function Type_In_Use
(T
: Entity_Id
) return Boolean;
2533 -- Check whether type or base type appear in an active use_type clause
2535 ------------------------------
2536 -- Preserve_Full_Attributes --
2537 ------------------------------
2539 procedure Preserve_Full_Attributes
(Priv
, Full
: Entity_Id
) is
2540 Priv_Is_Base_Type
: constant Boolean := Is_Base_Type
(Priv
);
2543 Set_Size_Info
(Priv
, (Full
));
2544 Set_RM_Size
(Priv
, RM_Size
(Full
));
2545 Set_Size_Known_At_Compile_Time
2546 (Priv
, Size_Known_At_Compile_Time
(Full
));
2547 Set_Is_Volatile
(Priv
, Is_Volatile
(Full
));
2548 Set_Treat_As_Volatile
(Priv
, Treat_As_Volatile
(Full
));
2549 Set_Is_Ada_2005_Only
(Priv
, Is_Ada_2005_Only
(Full
));
2550 Set_Is_Ada_2012_Only
(Priv
, Is_Ada_2012_Only
(Full
));
2551 Set_Has_Pragma_Unmodified
(Priv
, Has_Pragma_Unmodified
(Full
));
2552 Set_Has_Pragma_Unreferenced
(Priv
, Has_Pragma_Unreferenced
(Full
));
2553 Set_Has_Pragma_Unreferenced_Objects
2554 (Priv
, Has_Pragma_Unreferenced_Objects
2556 if Is_Unchecked_Union
(Full
) then
2557 Set_Is_Unchecked_Union
(Base_Type
(Priv
));
2559 -- Why is atomic not copied here ???
2561 if Referenced
(Full
) then
2562 Set_Referenced
(Priv
);
2565 if Priv_Is_Base_Type
then
2566 Set_Is_Controlled
(Priv
, Is_Controlled
(Base_Type
(Full
)));
2567 Set_Finalize_Storage_Only
2568 (Priv
, Finalize_Storage_Only
2569 (Base_Type
(Full
)));
2570 Set_Has_Task
(Priv
, Has_Task
(Base_Type
(Full
)));
2571 Set_Has_Protected
(Priv
, Has_Protected
(Base_Type
(Full
)));
2572 Set_Has_Controlled_Component
2573 (Priv
, Has_Controlled_Component
2574 (Base_Type
(Full
)));
2577 Set_Freeze_Node
(Priv
, Freeze_Node
(Full
));
2579 -- Propagate information of type invariants, which may be specified
2580 -- for the full view.
2582 if Has_Invariants
(Full
) and not Has_Invariants
(Priv
) then
2583 Set_Has_Invariants
(Priv
);
2584 Set_Subprograms_For_Type
(Priv
, Subprograms_For_Type
(Full
));
2587 if Is_Tagged_Type
(Priv
)
2588 and then Is_Tagged_Type
(Full
)
2589 and then not Error_Posted
(Full
)
2591 if Is_Tagged_Type
(Priv
) then
2593 -- If the type is tagged, the tag itself must be available on
2594 -- the partial view, for expansion purposes.
2596 Set_First_Entity
(Priv
, First_Entity
(Full
));
2598 -- If there are discriminants in the partial view, these remain
2599 -- visible. Otherwise only the tag itself is visible, and there
2600 -- are no nameable components in the partial view.
2602 if No
(Last_Entity
(Priv
)) then
2603 Set_Last_Entity
(Priv
, First_Entity
(Priv
));
2607 Set_Has_Discriminants
(Priv
, Has_Discriminants
(Full
));
2609 if Has_Discriminants
(Full
) then
2610 Set_Discriminant_Constraint
(Priv
,
2611 Discriminant_Constraint
(Full
));
2614 end Preserve_Full_Attributes
;
2620 function Type_In_Use
(T
: Entity_Id
) return Boolean is
2622 return Scope
(Base_Type
(T
)) = P
2623 and then (In_Use
(T
) or else In_Use
(Base_Type
(T
)));
2626 -- Start of processing for Uninstall_Declarations
2629 Id
:= First_Entity
(P
);
2630 while Present
(Id
) and then Id
/= First_Private_Entity
(P
) loop
2631 if Debug_Flag_E
then
2632 Write_Str
("unlinking visible entity ");
2633 Write_Int
(Int
(Id
));
2637 -- On exit from the package scope, we must preserve the visibility
2638 -- established by use clauses in the current scope. Two cases:
2640 -- a) If the entity is an operator, it may be a primitive operator of
2641 -- a type for which there is a visible use-type clause.
2643 -- b) for other entities, their use-visibility is determined by a
2644 -- visible use clause for the package itself. For a generic instance,
2645 -- the instantiation of the formals appears in the visible part,
2646 -- but the formals are private and remain so.
2648 if Ekind
(Id
) = E_Function
2649 and then Is_Operator_Symbol_Name
(Chars
(Id
))
2650 and then not Is_Hidden
(Id
)
2651 and then not Error_Posted
(Id
)
2653 Set_Is_Potentially_Use_Visible
(Id
,
2655 or else Type_In_Use
(Etype
(Id
))
2656 or else Type_In_Use
(Etype
(First_Formal
(Id
)))
2657 or else (Present
(Next_Formal
(First_Formal
(Id
)))
2660 (Etype
(Next_Formal
(First_Formal
(Id
))))));
2662 if In_Use
(P
) and then not Is_Hidden
(Id
) then
2664 -- A child unit of a use-visible package remains use-visible
2665 -- only if it is itself a visible child unit. Otherwise it
2666 -- would remain visible in other contexts where P is use-
2667 -- visible, because once compiled it stays in the entity list
2668 -- of its parent unit.
2670 if Is_Child_Unit
(Id
) then
2671 Set_Is_Potentially_Use_Visible
2672 (Id
, Is_Visible_Lib_Unit
(Id
));
2674 Set_Is_Potentially_Use_Visible
(Id
);
2678 Set_Is_Potentially_Use_Visible
(Id
, False);
2682 -- Local entities are not immediately visible outside of the package
2684 Set_Is_Immediately_Visible
(Id
, False);
2686 -- If this is a private type with a full view (for example a local
2687 -- subtype of a private type declared elsewhere), ensure that the
2688 -- full view is also removed from visibility: it may be exposed when
2689 -- swapping views in an instantiation.
2691 if Is_Type
(Id
) and then Present
(Full_View
(Id
)) then
2692 Set_Is_Immediately_Visible
(Full_View
(Id
), False);
2695 if Is_Tagged_Type
(Id
) and then Ekind
(Id
) = E_Record_Type
then
2696 Check_Abstract_Overriding
(Id
);
2697 Check_Conventions
(Id
);
2700 if Ekind_In
(Id
, E_Private_Type
, E_Limited_Private_Type
)
2701 and then No
(Full_View
(Id
))
2702 and then not Is_Generic_Type
(Id
)
2703 and then not Is_Derived_Type
(Id
)
2705 Error_Msg_N
("missing full declaration for private type&", Id
);
2707 elsif Ekind
(Id
) = E_Record_Type_With_Private
2708 and then not Is_Generic_Type
(Id
)
2709 and then No
(Full_View
(Id
))
2711 if Nkind
(Parent
(Id
)) = N_Private_Type_Declaration
then
2712 Error_Msg_N
("missing full declaration for private type&", Id
);
2715 ("missing full declaration for private extension", Id
);
2718 -- Case of constant, check for deferred constant declaration with
2719 -- no full view. Likely just a matter of a missing expression, or
2720 -- accidental use of the keyword constant.
2722 elsif Ekind
(Id
) = E_Constant
2724 -- OK if constant value present
2726 and then No
(Constant_Value
(Id
))
2728 -- OK if full view present
2730 and then No
(Full_View
(Id
))
2732 -- OK if imported, since that provides the completion
2734 and then not Is_Imported
(Id
)
2736 -- OK if object declaration replaced by renaming declaration as
2737 -- a result of OK_To_Rename processing (e.g. for concatenation)
2739 and then Nkind
(Parent
(Id
)) /= N_Object_Renaming_Declaration
2741 -- OK if object declaration with the No_Initialization flag set
2743 and then not (Nkind
(Parent
(Id
)) = N_Object_Declaration
2744 and then No_Initialization
(Parent
(Id
)))
2746 -- If no private declaration is present, we assume the user did
2747 -- not intend a deferred constant declaration and the problem
2748 -- is simply that the initializing expression is missing.
2750 if not Has_Private_Declaration
(Etype
(Id
)) then
2752 -- We assume that the user did not intend a deferred constant
2753 -- declaration, and the expression is just missing.
2756 ("constant declaration requires initialization expression",
2759 if Is_Limited_Type
(Etype
(Id
)) then
2761 ("\if variable intended, remove CONSTANT from declaration",
2765 -- Otherwise if a private declaration is present, then we are
2766 -- missing the full declaration for the deferred constant.
2770 ("missing full declaration for deferred constant (RM 7.4)",
2773 if Is_Limited_Type
(Etype
(Id
)) then
2775 ("\if variable intended, remove CONSTANT from declaration",
2784 -- If the specification was installed as the parent of a public child
2785 -- unit, the private declarations were not installed, and there is
2788 if not In_Private_Part
(P
) then
2791 Set_In_Private_Part
(P
, False);
2794 -- Make private entities invisible and exchange full and private
2795 -- declarations for private types. Id is now the first private entity
2798 while Present
(Id
) loop
2799 if Debug_Flag_E
then
2800 Write_Str
("unlinking private entity ");
2801 Write_Int
(Int
(Id
));
2805 if Is_Tagged_Type
(Id
) and then Ekind
(Id
) = E_Record_Type
then
2806 Check_Abstract_Overriding
(Id
);
2807 Check_Conventions
(Id
);
2810 Set_Is_Immediately_Visible
(Id
, False);
2812 if Is_Private_Base_Type
(Id
) and then Present
(Full_View
(Id
)) then
2813 Full
:= Full_View
(Id
);
2815 -- If the partial view is not declared in the visible part of the
2816 -- package (as is the case when it is a type derived from some
2817 -- other private type in the private part of the current package),
2818 -- no exchange takes place.
2821 or else List_Containing
(Parent
(Id
)) /=
2822 Visible_Declarations
(Specification
(Decl
))
2827 -- The entry in the private part points to the full declaration,
2828 -- which is currently visible. Exchange them so only the private
2829 -- type declaration remains accessible, and link private and full
2830 -- declaration in the opposite direction. Before the actual
2831 -- exchange, we copy back attributes of the full view that must
2832 -- be available to the partial view too.
2834 Preserve_Full_Attributes
(Id
, Full
);
2836 Set_Is_Potentially_Use_Visible
(Id
, In_Use
(P
));
2838 -- The following test may be redundant, as this is already
2839 -- diagnosed in sem_ch3. ???
2841 if Is_Indefinite_Subtype
(Full
)
2842 and then not Is_Indefinite_Subtype
(Id
)
2844 Error_Msg_Sloc
:= Sloc
(Parent
(Id
));
2846 ("full view of& not compatible with declaration#", Full
, Id
);
2849 -- Swap out the subtypes and derived types of Id that
2850 -- were compiled in this scope, or installed previously
2851 -- by Install_Private_Declarations.
2853 -- Before we do the swap, we verify the presence of the Full_View
2854 -- field which may be empty due to a swap by a previous call to
2855 -- End_Package_Scope (e.g. from the freezing mechanism).
2857 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Id
));
2858 while Present
(Priv_Elmt
) loop
2859 Priv_Sub
:= Node
(Priv_Elmt
);
2861 if Present
(Full_View
(Priv_Sub
)) then
2862 if Scope
(Priv_Sub
) = P
2863 or else not In_Open_Scopes
(Scope
(Priv_Sub
))
2865 Set_Is_Immediately_Visible
(Priv_Sub
, False);
2868 if Is_Visible_Dependent
(Priv_Sub
) then
2869 Preserve_Full_Attributes
2870 (Priv_Sub
, Full_View
(Priv_Sub
));
2871 Replace_Elmt
(Priv_Elmt
, Full_View
(Priv_Sub
));
2872 Exchange_Declarations
(Priv_Sub
);
2876 Next_Elmt
(Priv_Elmt
);
2879 -- Now restore the type itself to its private view
2881 Exchange_Declarations
(Id
);
2883 -- If we have installed an underlying full view for a type derived
2884 -- from a private type in a child unit, restore the proper views
2885 -- of private and full view. See corresponding code in
2886 -- Install_Private_Declarations.
2888 -- After the exchange, Full denotes the private type in the
2889 -- visible part of the package.
2891 if Is_Private_Base_Type
(Full
)
2892 and then Present
(Full_View
(Full
))
2893 and then Present
(Underlying_Full_View
(Full
))
2894 and then In_Package_Body
(Current_Scope
)
2896 Set_Full_View
(Full
, Underlying_Full_View
(Full
));
2897 Set_Underlying_Full_View
(Full
, Empty
);
2900 elsif Ekind
(Id
) = E_Incomplete_Type
2901 and then Comes_From_Source
(Id
)
2902 and then No
(Full_View
(Id
))
2904 -- Mark Taft amendment types. Verify that there are no primitive
2905 -- operations declared for the type (3.10.1(9)).
2907 Set_Has_Completion_In_Body
(Id
);
2914 Elmt
:= First_Elmt
(Private_Dependents
(Id
));
2915 while Present
(Elmt
) loop
2916 Subp
:= Node
(Elmt
);
2918 -- Is_Primitive is tested because there can be cases where
2919 -- nonprimitive subprograms (in nested packages) are added
2920 -- to the Private_Dependents list.
2922 if Is_Overloadable
(Subp
) and then Is_Primitive
(Subp
) then
2924 ("type& must be completed in the private part",
2927 -- The result type of an access-to-function type cannot be a
2928 -- Taft-amendment type, unless the version is Ada 2012 or
2929 -- later (see AI05-151).
2931 elsif Ada_Version
< Ada_2012
2932 and then Ekind
(Subp
) = E_Subprogram_Type
2934 if Etype
(Subp
) = Id
2936 (Is_Class_Wide_Type
(Etype
(Subp
))
2937 and then Etype
(Etype
(Subp
)) = Id
)
2940 ("type& must be completed in the private part",
2941 Associated_Node_For_Itype
(Subp
), Id
);
2949 elsif not Is_Child_Unit
(Id
)
2950 and then (not Is_Private_Type
(Id
) or else No
(Full_View
(Id
)))
2953 Set_Is_Potentially_Use_Visible
(Id
, False);
2959 end Uninstall_Declarations
;
2961 ------------------------
2962 -- Unit_Requires_Body --
2963 ------------------------
2965 function Unit_Requires_Body
2966 (Pack_Id
: Entity_Id
;
2967 Ignore_Abstract_State
: Boolean := False) return Boolean
2972 -- Imported entity never requires body. Right now, only subprograms can
2973 -- be imported, but perhaps in the future we will allow import of
2976 if Is_Imported
(Pack_Id
) then
2979 -- Body required if library package with pragma Elaborate_Body
2981 elsif Has_Pragma_Elaborate_Body
(Pack_Id
) then
2984 -- Body required if subprogram
2986 elsif Is_Subprogram_Or_Generic_Subprogram
(Pack_Id
) then
2989 -- Treat a block as requiring a body
2991 elsif Ekind
(Pack_Id
) = E_Block
then
2994 elsif Ekind
(Pack_Id
) = E_Package
2995 and then Nkind
(Parent
(Pack_Id
)) = N_Package_Specification
2996 and then Present
(Generic_Parent
(Parent
(Pack_Id
)))
2999 G_P
: constant Entity_Id
:= Generic_Parent
(Parent
(Pack_Id
));
3001 if Has_Pragma_Elaborate_Body
(G_P
) then
3006 -- A [generic] package that introduces at least one non-null abstract
3007 -- state requires completion. However, there is a separate rule that
3008 -- requires that such a package have a reason other than this for a
3009 -- body being required (if necessary a pragma Elaborate_Body must be
3010 -- provided). If Ignore_Abstract_State is True, we don't do this check
3011 -- (so we can use Unit_Requires_Body to check for some other reason).
3013 elsif Ekind_In
(Pack_Id
, E_Generic_Package
, E_Package
)
3014 and then not Ignore_Abstract_State
3015 and then Present
(Abstract_States
(Pack_Id
))
3016 and then not Is_Null_State
3017 (Node
(First_Elmt
(Abstract_States
(Pack_Id
))))
3022 -- Otherwise search entity chain for entity requiring completion
3024 E
:= First_Entity
(Pack_Id
);
3025 while Present
(E
) loop
3026 if Requires_Completion_In_Body
(E
, Pack_Id
) then
3034 end Unit_Requires_Body
;
3036 -----------------------------
3037 -- Unit_Requires_Body_Info --
3038 -----------------------------
3040 procedure Unit_Requires_Body_Info
(Pack_Id
: Entity_Id
) is
3044 -- An imported entity never requires body. Right now, only subprograms
3045 -- can be imported, but perhaps in the future we will allow import of
3048 if Is_Imported
(Pack_Id
) then
3051 -- Body required if library package with pragma Elaborate_Body
3053 elsif Has_Pragma_Elaborate_Body
(Pack_Id
) then
3054 Error_Msg_N
("info: & requires body (Elaborate_Body)?Y?", Pack_Id
);
3056 -- Body required if subprogram
3058 elsif Is_Subprogram_Or_Generic_Subprogram
(Pack_Id
) then
3059 Error_Msg_N
("info: & requires body (subprogram case)?Y?", Pack_Id
);
3061 -- Body required if generic parent has Elaborate_Body
3063 elsif Ekind
(Pack_Id
) = E_Package
3064 and then Nkind
(Parent
(Pack_Id
)) = N_Package_Specification
3065 and then Present
(Generic_Parent
(Parent
(Pack_Id
)))
3068 G_P
: constant Entity_Id
:= Generic_Parent
(Parent
(Pack_Id
));
3070 if Has_Pragma_Elaborate_Body
(G_P
) then
3072 ("info: & requires body (generic parent Elaborate_Body)?Y?",
3077 -- A [generic] package that introduces at least one non-null abstract
3078 -- state requires completion. However, there is a separate rule that
3079 -- requires that such a package have a reason other than this for a
3080 -- body being required (if necessary a pragma Elaborate_Body must be
3081 -- provided). If Ignore_Abstract_State is True, we don't do this check
3082 -- (so we can use Unit_Requires_Body to check for some other reason).
3084 elsif Ekind_In
(Pack_Id
, E_Generic_Package
, E_Package
)
3085 and then Present
(Abstract_States
(Pack_Id
))
3086 and then not Is_Null_State
3087 (Node
(First_Elmt
(Abstract_States
(Pack_Id
))))
3090 ("info: & requires body (non-null abstract state aspect)?Y?",
3094 -- Otherwise search entity chain for entity requiring completion
3096 E
:= First_Entity
(Pack_Id
);
3097 while Present
(E
) loop
3098 if Requires_Completion_In_Body
(E
, Pack_Id
) then
3099 Error_Msg_Node_2
:= E
;
3101 ("info: & requires body (& requires completion)?Y?", E
, Pack_Id
);
3106 end Unit_Requires_Body_Info
;