===================================================================
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
+-- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -406,9 +406,25 @@
New_Child
(Load_Name, Get_Unit_Name (Name (Unit (Cunit (Unump)))));
+ -- If the load is for a with_clause, for visibility purposes both
+ -- the renamed entity and renaming one must be available in the
+ -- current unit: the renamed one in order to retrieve the child
+ -- unit, and the original one because it may be used as a prefix
+ -- in the body of the current unit. We add an explicit with_clause
+ -- for the original parent so that the renaming declaration is
+ -- properly loaded and analyzed.
+
+ if Present (With_Node) then
+ Insert_After (With_Node,
+ Make_With_Clause (Sloc (With_Node),
+ Name => Copy_Separate_Tree (Prefix (Name (With_Node)))));
+ end if;
+
-- Save the renaming entity, to establish its visibility when
-- installing the context. The implicit with is on this entity,
- -- not on the package it renames.
+ -- not on the package it renames. This is somewhat redundant given
+ -- the with_clause just created, but it simplifies subsequent
+ -- expansion of the current with_clause. Optimizable ???
if Nkind (Error_Node) = N_With_Clause
and then Nkind (Name (Error_Node)) = N_Selected_Component
===================================================================
@@ -2936,33 +2936,12 @@
function Build_Unit_Name (Nam : Node_Id) return Node_Id is
Ent : Entity_Id;
- Renaming : Entity_Id;
Result : Node_Id;
begin
if Nkind (Nam) = N_Identifier then
+ return New_Occurrence_Of (Entity (Nam), Loc);
- -- If the parent unit P in the name of the with_clause for P.Q is
- -- a renaming of package R, then the entity of the parent is set
- -- to R, but the identifier retains Chars (P) to be consistent
- -- with the source (see details in lib-load). However the implicit
- -- with_clause for the parent must make the entity for P visible,
- -- because P.Q may be used as a prefix within the current unit.
- -- The entity for P is the current_entity with that name, because
- -- the package renaming declaration for it has just been analyzed.
- -- Note that this case can only happen if P.Q has already appeared
- -- in a previous with_clause in a related unit, such as the
- -- library body of the current unit.
-
- if Chars (Nam) /= Chars (Entity (Nam)) then
- Renaming := Current_Entity (Nam);
- pragma Assert (Renamed_Entity (Renaming) = Entity (Nam));
- return New_Occurrence_Of (Renaming, Loc);
-
- else
- return New_Occurrence_Of (Entity (Nam), Loc);
- end if;
-
else
Ent := Entity (Nam);