[Ada] Inheritance of variables in extending projects

Arnaud Charlet charlet@adacore.com
Wed Jul 30 10:11:00 GMT 2014


A variable V declared in a project A that is extended by a project B is
now inherited in project B; it can be referenced as V in project B or as
B.V in any other project that imports B.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-07-30  Vincent Celier  <celier@adacore.com>

	* prj-proc.adb (Imported_Or_Extended_Project_From): New Boolean
	parameter No_Extending, defaulted to False. When No_Extending
	is True, do not look for an extending project.
	(Expression): For a variable reference that is not for the current
	project, get its Id calling Imported_Or_Extended_Project_From
	with No_Extending set to True.
	* prj-strt.adb (Parse_Variable_Reference): If a referenced
	variable is not found in the current project, check if it is
	defined in one of the projects it extends.

-------------- next part --------------
Index: prj-proc.adb
===================================================================
--- prj-proc.adb	(revision 213201)
+++ prj-proc.adb	(working copy)
@@ -118,8 +118,9 @@
    --  of an expression and return it as a Variable_Value.
 
    function Imported_Or_Extended_Project_From
-     (Project   : Project_Id;
-      With_Name : Name_Id) return Project_Id;
+     (Project      : Project_Id;
+      With_Name    : Name_Id;
+      No_Extending : Boolean := False) return Project_Id;
    --  Find an imported or extended project of Project whose name is With_Name
 
    function Package_From
@@ -705,8 +706,9 @@
                      The_Name :=
                        Name_Of (Term_Project, From_Project_Node_Tree);
                      The_Project := Imported_Or_Extended_Project_From
-                                      (Project   => Project,
-                                       With_Name => The_Name);
+                                      (Project      => Project,
+                                       With_Name    => The_Name,
+                                       No_Extending => True);
                   end if;
 
                   if Present (Term_Package) then
@@ -1261,8 +1263,9 @@
    ---------------------------------------
 
    function Imported_Or_Extended_Project_From
-     (Project   : Project_Id;
-      With_Name : Name_Id) return Project_Id
+     (Project      : Project_Id;
+      With_Name    : Name_Id;
+      No_Extending : Boolean := False) return Project_Id
    is
       List        : Project_List;
       Result      : Project_Id;
@@ -1304,7 +1307,12 @@
             Proj := Result.Extends;
             while Proj /= No_Project loop
                if Proj.Name = With_Name then
-                  Temp_Result := Result;
+                  if No_Extending then
+                     Temp_Result := Proj;
+                  else
+                     Temp_Result := Result;
+                  end if;
+
                   exit;
                end if;
 
Index: prj-strt.adb
===================================================================
--- prj-strt.adb	(revision 213201)
+++ prj-strt.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2014, 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- --
@@ -1162,7 +1162,7 @@
 
             --  If we have not found the variable in the package, check if the
             --  variable has been declared in the project, or in any of its
-            --  ancestors.
+            --  ancestors, or in any of the project it extends.
 
             if No (Current_Variable) then
                declare
@@ -1182,8 +1182,15 @@
 
                      exit when Present (Current_Variable);
 
-                     Proj := Parent_Project_Of (Proj, In_Tree);
+                     if No (Parent_Project_Of (Proj, In_Tree)) then
+                        Proj :=
+                          Extended_Project_Of
+                            (Project_Declaration_Of (Proj, In_Tree), In_Tree);
 
+                     else
+                        Proj := Parent_Project_Of (Proj, In_Tree);
+                     end if;
+
                      Set_Project_Node_Of (Variable, In_Tree, To => Proj);
 
                      exit when No (Proj);


More information about the Gcc-patches mailing list