procedure Hide_Public_Entities (Decls : List_Id) is
function Has_Referencer
- (Decls : List_Id;
- Top_Level : Boolean := False) return Boolean;
+ (Decls : List_Id;
+ In_Nested_Instance : Boolean;
+ Has_Outer_Referencer_Of_Non_Subprograms : Boolean) return Boolean;
-- A "referencer" is a construct which may reference a previous
-- declaration. Examine all declarations in list Decls in reverse
- -- and determine whether once such referencer exists. All entities
+ -- and determine whether one such referencer exists. All entities
-- in the range Last (Decls) .. Referencer are hidden from external
-- visibility.
--------------------
function Has_Referencer
- (Decls : List_Id;
- Top_Level : Boolean := False) return Boolean
+ (Decls : List_Id;
+ In_Nested_Instance : Boolean;
+ Has_Outer_Referencer_Of_Non_Subprograms : Boolean) return Boolean
is
Decl : Node_Id;
Decl_Id : Entity_Id;
Spec : Node_Id;
- Has_Non_Subprograms_Referencer : Boolean := False;
+ Has_Referencer_Of_Non_Subprograms : Boolean :=
+ Has_Outer_Referencer_Of_Non_Subprograms;
-- Set if an inlined subprogram body was detected as a referencer.
-- In this case, we do not return True immediately but keep hiding
-- subprograms from external visibility.
elsif Nkind (Decl) = N_Package_Declaration then
Spec := Specification (Decl);
+ Decl_Id := Defining_Entity (Spec);
-- Inspect the declarations of a non-generic package to try
-- and hide more entities from external visibility.
- if not Is_Generic_Unit (Defining_Entity (Spec)) then
- if Has_Referencer (Private_Declarations (Spec))
- or else Has_Referencer (Visible_Declarations (Spec))
+ if not Is_Generic_Unit (Decl_Id) then
+ if Has_Referencer (Private_Declarations (Spec),
+ In_Nested_Instance
+ or else
+ Is_Generic_Instance (Decl_Id),
+ Has_Referencer_Of_Non_Subprograms)
+ or else
+ Has_Referencer (Visible_Declarations (Spec),
+ In_Nested_Instance
+ or else
+ Is_Generic_Instance (Decl_Id),
+ Has_Referencer_Of_Non_Subprograms)
then
return True;
end if;
-- Inspect the declarations of a non-generic package body to
-- try and hide more entities from external visibility.
- elsif Has_Referencer (Declarations (Decl)) then
+ elsif Has_Referencer (Declarations (Decl),
+ In_Nested_Instance
+ or else
+ Is_Generic_Instance (Decl_Id),
+ Has_Referencer_Of_Non_Subprograms)
+ then
return True;
end if;
if Is_Inlined (Decl_Id)
or else Has_Pragma_Inline (Decl_Id)
then
- Has_Non_Subprograms_Referencer := True;
+ Has_Referencer_Of_Non_Subprograms := True;
-- Inspect the statements of the subprogram body
-- to determine whether the body references other
if Is_Inlined (Decl_Id)
or else Has_Pragma_Inline (Decl_Id)
then
- Has_Non_Subprograms_Referencer := True;
+ Has_Referencer_Of_Non_Subprograms := True;
-- Inspect the statements of the subprogram body
-- to determine whether the body references other
begin
-- Inspect the actions to find references to subprograms
- Discard := Has_Referencer (Actions (Decl));
+ Discard :=
+ Has_Referencer (Actions (Decl),
+ In_Nested_Instance,
+ Has_Referencer_Of_Non_Subprograms);
end;
-- Exceptions, objects and renamings do not need to be public
-- if they are not followed by a construct which can reference
- -- and export them. The Is_Public flag is reset on top level
- -- entities only as anything nested is local to its context.
- -- Likewise for subprograms, but we work harder for them.
-
+ -- and export them. Likewise for subprograms but we work harder
+ -- for them to see whether they are referenced on an individual
+ -- basis by looking into the table of referenced subprograms.
+ -- But we cannot say anything for entities declared in nested
+ -- instances because instantiations are not done yet so the
+ -- bodies are not visible and could contain references to them.
elsif Nkind_In (Decl, N_Exception_Declaration,
N_Object_Declaration,
N_Object_Renaming_Declaration,
then
Decl_Id := Defining_Entity (Decl);
- if Top_Level
+ if not In_Nested_Instance
and then not Is_Imported (Decl_Id)
and then not Is_Exported (Decl_Id)
and then No (Interface_Name (Decl_Id))
and then
- (not Has_Non_Subprograms_Referencer
+ (not Has_Referencer_Of_Non_Subprograms
or else (Nkind (Decl) = N_Subprogram_Declaration
and then not Subprogram_Table.Get (Decl_Id)))
then
Prev (Decl);
end loop;
- return Has_Non_Subprograms_Referencer;
+ return Has_Referencer_Of_Non_Subprograms;
end Has_Referencer;
-------------------------
Traversed_Table.Reset;
Subprogram_Table.Reset;
- Discard := Has_Referencer (Decls, Top_Level => True);
+ Discard := Has_Referencer (Decls, False, False);
end Hide_Public_Entities;
----------------------------------