]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
sem_ch10.adb (Build_Unit_Name): If the unit name in a with_clause has the form A...
authorEd Schonberg <schonberg@adacore.com>
Thu, 31 Jul 2008 13:31:37 +0000 (15:31 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 31 Jul 2008 13:31:37 +0000 (15:31 +0200)
2008-07-31  Ed Schonberg  <schonberg@adacore.com>

* sem_ch10.adb (Build_Unit_Name): If the unit name in a with_clause
has the form A.B.C and B is a unit renaming, analyze its compilation
unit and add a with_clause on A.b to the context.

From-SVN: r138408

gcc/ada/sem_ch10.adb

index 540b2a6d85dc11ce248ffa8c51a00be50a11cc68..626bee47c1a8924f1c741e02bd5a622e16a343a7 100644 (file)
@@ -2660,13 +2660,18 @@ package body Sem_Ch10 is
       P     : Node_Id;
 
       function Build_Unit_Name (Nam : Node_Id) return Node_Id;
-      --  Comment required here ???
+      --  Build name to be used in implicit with_clause. In most cases this
+      --  is the source name, but if renamings are present we must make the
+      --  original unit visible, not the one it renames. The entity in the
+      --  use clause is the renamed unit, but the identifier is the one from
+      --  the source, which allows us to recover the unit renaming.
 
       ---------------------
       -- Build_Unit_Name --
       ---------------------
 
       function Build_Unit_Name (Nam : Node_Id) return Node_Id is
+         Ent      : Entity_Id;
          Renaming : Entity_Id;
          Result   : Node_Id;
 
@@ -2695,12 +2700,34 @@ package body Sem_Ch10 is
             end if;
 
          else
+            Ent := Entity (Nam);
+
+            if Present (Entity (Selector_Name (Nam)))
+              and then Chars (Entity (Selector_Name (Nam))) /= Chars (Ent)
+              and then
+                Nkind (Unit_Declaration_Node (Entity (Selector_Name (Nam))))
+                  = N_Package_Renaming_Declaration
+            then
+
+               --  The name in the with_clause is of the form A.B.C, and B
+               --  is given by a renaming declaration. In that case we may
+               --  not have analyzed the unit for B, but replaced it directly
+               --  in lib-load with the unit it renames. We have to make A.B
+               --  visible, so analyze the declaration for B now, in case it
+               --  has not been done yet.
+
+               Ent :=  Entity (Selector_Name (Nam));
+               Analyze
+                 (Parent
+                   (Unit_Declaration_Node (Entity (Selector_Name (Nam)))));
+            end if;
+
             Result :=
               Make_Expanded_Name (Loc,
                 Chars  => Chars (Entity (Nam)),
                 Prefix => Build_Unit_Name (Prefix (Nam)),
-                Selector_Name => New_Occurrence_Of (Entity (Nam), Loc));
-            Set_Entity (Result, Entity (Nam));
+                Selector_Name => New_Occurrence_Of (Ent, Loc));
+            Set_Entity (Result, Ent);
             return Result;
          end if;
       end Build_Unit_Name;