From: Denis Mazzucato <[email protected]>
Improve consistency of the warning message when child units are hiding other
with'ed homonym package, regardless of the order of the context clauses.
gcc/ada/ChangeLog:
* sem_ch10.adb (Install_Siblings): Fix condition to emit warning.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_ch10.adb | 72 +++++++++++++++++++++++---------------------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index ffd3eaa6bec1..cff0d71c17ce 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -176,7 +176,7 @@ package body Sem_Ch10 is
-- use-package clauses to avoid circularities when installing context.
procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id);
- -- In the compilation of a child unit, a child of any of the ancestor
+ -- In the compilation of a child unit, a child of any of the ancestor
-- units is directly visible if it is visible, because the parent is in
-- an enclosing scope. Iterate over context to find child units of U_Name
-- or of some ancestor of it.
@@ -4803,9 +4803,8 @@ package body Sem_Ch10 is
----------------------
procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
- Item : Node_Id;
- Id : Entity_Id;
- Prev : Entity_Id;
+ Item : Node_Id;
+ Item_E : Entity_Id;
begin
-- Iterate over explicit with clauses, and check whether the scope of
@@ -4836,42 +4835,46 @@ package body Sem_Ch10 is
or else Private_Present (N)
or else Nkind (Unit (N)) = N_Package_Body
then
- Id := Entity (Name (Item));
+ Item_E := Entity (Name (Item));
- if Is_Child_Unit (Id)
- and then Is_Ancestor_Package (Scope (Id), U_Name)
+ if Is_Child_Unit (Item_E)
+ and then Is_Ancestor_Package (Scope (Item_E), U_Name)
then
- Set_Is_Immediately_Visible (Id);
+ Set_Is_Immediately_Visible (Item_E);
-- Check for the presence of another unit in the context that
-- may be inadvertently hidden by the child.
- Prev := Current_Entity (Id);
+ declare
+ Clause : Node_Id;
+ Clause_E : Entity_Id;
- if Present (Prev)
- and then Is_Immediately_Visible (Prev)
- and then not Is_Child_Unit (Prev)
- then
- declare
- Clause : Node_Id;
+ begin
+ Clause := First (Context_Items (N));
+ while Present (Clause) loop
+ if Clause /= Item
+ and then Nkind (Clause) = N_With_Clause
+ and then not Limited_Present (Clause)
+ then
+ Clause_E := Entity (Name (Clause));
- begin
- Clause := First (Context_Items (N));
- while Present (Clause) loop
- if Nkind (Clause) = N_With_Clause
- and then Entity (Name (Clause)) = Prev
+ if not Is_Ancestor_Package (Clause_E, U_Name)
+ and then Chars (Clause_E) = Chars (Item_E)
+ and then not Has_Prefix (Name (Clause))
+ and then not In_Use (Clause_E)
then
Error_Msg_NE
- ("child unit& hides compilation unit " &
- "with the same name??",
- Name (Item), Id);
+ ("child unit& hides compilation unit "
+ & "with the same name??",
+ Name (Item),
+ Item_E);
exit;
end if;
+ end if;
- Next (Clause);
- end loop;
- end;
- end if;
+ Next (Clause);
+ end loop;
+ end;
-- The With_Clause may be on a grandchild or one of its further
-- descendants, which makes a child immediately visible. Examine
@@ -4879,12 +4882,12 @@ package body Sem_Ch10 is
-- if current unit is A.C, and with_clause is on A.X.Y.Z, then X
-- is immediately visible.
- elsif Is_Child_Unit (Id) then
+ elsif Is_Child_Unit (Item_E) then
declare
Par : Entity_Id;
begin
- Par := Scope (Id);
+ Par := Scope (Item_E);
while Is_Child_Unit (Par) loop
if Is_Ancestor_Package (Scope (Par), U_Name) then
Set_Is_Immediately_Visible (Par);
@@ -4902,9 +4905,9 @@ package body Sem_Ch10 is
-- is already a regular with_clause for it in the current unit.
elsif Private_Present (Item) then
- Id := Entity (Name (Item));
+ Item_E := Entity (Name (Item));
- if Is_Child_Unit (Id) then
+ if Is_Child_Unit (Item_E) then
declare
Clause : Node_Id;
@@ -4928,12 +4931,13 @@ package body Sem_Ch10 is
and then Is_Entity_Name (Name (Clause))
and then not Private_Present (Clause)
then
- if Entity (Name (Clause)) = Id
+ if Entity (Name (Clause)) = Item_E
or else
(Nkind (Name (Clause)) = N_Expanded_Name
and then
Is_Entity_Name (Prefix (Name (Clause)))
- and then Entity (Prefix (Name (Clause))) = Id)
+ and then Entity (Prefix (Name (Clause)))
+ = Item_E)
then
return True;
end if;
@@ -4946,7 +4950,7 @@ package body Sem_Ch10 is
end In_Context;
begin
- Set_Is_Visible_Lib_Unit (Id, In_Context);
+ Set_Is_Visible_Lib_Unit (Item_E, In_Context);
end;
end if;
end if;
--
2.43.0