[Ada] Parent_Unit_Names and unit renaming declarations
Arnaud Charlet
charlet@adacore.com
Fri Oct 22 09:32:00 GMT 2010
If the parent unit name that appears in a with_clause denotes a renaming
declaration, the parser has already retrieved the renamed unit in order to
obtain the real library unit denoted by the clause. If the parent unit nsme
is a simple name we set its entity to be the renamed unit. If the parent unit
name is itself a child unit, the prefix of its name is irrelevant to subsequent
visibility, and we replace it directly with a reference to the renamed unit.
Compiling and executing main.adb below must yield;
P2
P2.Sub
P2
P2.Sub
-----
with Root.P1;
with Root.P1.Sub;
with P3;
procedure Main is
begin
Root.P1.Proc;
Root.P1.Sub.Proc;
P3.Run;
end Main;
---
package Root is
procedure proc;
end Root;
---
package P2 is
procedure Proc;
end P2;
---
package P3 is
procedure Run;
end P3;
---
with P2;
package Root.P1 renames P2;
---
with Ada.Text_IO;
package body P2.Sub is
procedure Proc is
begin
Ada.Text_IO.Put_Line ("P2.Sub");
end Proc;
end P2.Sub;
---
package P2.Sub is
procedure Proc;
end P2.Sub;
---
with Ada.Text_IO;
package body P2 is
procedure Proc is
begin
Ada.Text_IO.Put_Line ("P2");
end Proc;
end P2;
---
with Root.P1;
with Root.P1.Sub;
package body P3 is
procedure Run is
begin
Root.P1.Proc;
Root.P1.Sub.Proc;
end Run;
end P3;
---
with Ada.Text_IO;
package body Root is
procedure Proc is
begin
Ada.Text_IO.Put_Line ("Root");
end Proc;
end Root;
---
Tested on x86_64-pc-linux-gnu, committed on trunk
2010-10-22 Ed Schonberg <schonberg@adacore.com>
* sem_ch10.adb (Analyze_With_Clause): If the parent_unit_name in a with
clause is a child unit that denotes a renaming, replace the
parent_unit_name with a reference to the renamed unit, because the
prefix is irrelevant to subsequent visibility..
-------------- next part --------------
Index: sem_ch10.adb
===================================================================
--- sem_ch10.adb (revision 165803)
+++ sem_ch10.adb (working copy)
@@ -2556,6 +2556,22 @@ package body Sem_Ch10 is
Par_Name := Scope (E_Name);
while Nkind (Pref) = N_Selected_Component loop
Change_Selected_Component_To_Expanded_Name (Pref);
+
+ if Present (Entity (Selector_Name (Pref)))
+ and then
+ Present (Renamed_Entity (Entity (Selector_Name (Pref))))
+ and then Entity (Selector_Name (Pref)) /= Par_Name
+ then
+
+ -- The prefix is a child unit that denotes a renaming
+ -- declaration. Replace the prefix directly with the renamed
+ -- unit, because the rest of the prefix is irrelevant to the
+ -- visibility of the real unit.
+
+ Rewrite (Pref, New_Occurrence_Of (Par_Name, Sloc (Pref)));
+ exit;
+ end if;
+
Set_Entity_With_Style_Check (Pref, Par_Name);
Generate_Reference (Par_Name, Pref);
More information about the Gcc-patches
mailing list