Patchwork [Ada] Package extensions in project files

login
register
mail settings
Submitter Arnaud Charlet
Date Sept. 10, 2010, 3:53 p.m.
Message ID <20100910155331.GA3182@adacore.com>
Download mbox | patch
Permalink /patch/64409/
State New
Headers show

Comments

Arnaud Charlet - Sept. 10, 2010, 3:53 p.m.
It is now allowed to extend a package with the same name from an imported
or extended project. The test for this is to invoke gnatmake on project
prj.gpr:

project Empty is
   for Source_Files use ();

   package Compiler is
      for Switches ("Ada") use ("-O2");
   end Compiler;
end Empty;

with "empty.gpr";
project Prj is
   for Main use ("main.adb");

   package Compiler extends Empty.Compiler is
      for Switches ("Ada") use Compiler'Switches ("Ada") & ("-g");
   end Compiler;
end Prj;

Sources of project Prj should be compiled with -O2 -g.

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

2010-09-10  Vincent Celier  <celier@adacore.com>

	* prj-dect.adb (Parse_Package_Declaration): Allow a package to extend
	a package with the same name from an imported or extended project.
	* prj-proc.adb (Process_Declarative_Items): Process package extensions

Patch

Index: prj-proc.adb
===================================================================
--- prj-proc.adb	(revision 164167)
+++ prj-proc.adb	(working copy)
@@ -1428,7 +1428,7 @@ 
 
                      if Present (Project_Of_Renamed_Package) then
 
-                        --  Renamed package
+                        --  Renamed or extending package
 
                         declare
                            Project_Name : constant Name_Id :=
@@ -1466,8 +1466,6 @@ 
                               In_Tree    => In_Tree);
                         end;
 
-                     --  Standard package declaration, not renaming
-
                      else
                         --  Set the default values of the attributes
 
@@ -1482,19 +1480,22 @@ 
                                 (Current_Item, From_Project_Node_Tree)),
                            Project_Level => False);
 
-                        --  And process declarative items of the new package
+                     end if;
 
-                        Process_Declarative_Items
-                          (Project                => Project,
-                           In_Tree                => In_Tree,
-                           Flags                  => Flags,
-                           From_Project_Node      => From_Project_Node,
-                           From_Project_Node_Tree => From_Project_Node_Tree,
-                           Pkg                    => New_Pkg,
-                           Item                   =>
-                             First_Declarative_Item_Of
-                               (Current_Item, From_Project_Node_Tree));
-                     end if;
+                     --  Process declarative items (nothing to do when the
+                     --  package is renaming, as the first declarative item is
+                     --  null).
+
+                     Process_Declarative_Items
+                       (Project                => Project,
+                        In_Tree                => In_Tree,
+                        Flags                  => Flags,
+                        From_Project_Node      => From_Project_Node,
+                        From_Project_Node_Tree => From_Project_Node_Tree,
+                        Pkg                    => New_Pkg,
+                        Item                   =>
+                          First_Declarative_Item_Of
+                            (Current_Item, From_Project_Node_Tree));
                   end;
                end if;
 
Index: prj-dect.adb
===================================================================
--- prj-dect.adb	(revision 164167)
+++ prj-dect.adb	(working copy)
@@ -1027,8 +1027,9 @@ 
       First_Attribute        : Attribute_Node_Id := Empty_Attribute;
       Current_Package        : Package_Node_Id   := Empty_Package;
       First_Declarative_Item : Project_Node_Id   := Empty_Node;
-
       Package_Location       : constant Source_Ptr := Token_Ptr;
+      Renaming               : Boolean := False;
+      Extending              : Boolean := False;
 
    begin
       Package_Declaration :=
@@ -1149,13 +1150,20 @@ 
       end if;
 
       if Token = Tok_Renames then
+         Renaming := True;
+      elsif Token = Tok_Extends then
+         Extending := True;
+      end if;
+
+      if Renaming or else Extending then
          if Is_Config_File then
             Error_Msg
               (Flags,
-               "no package renames in configuration projects", Token_Ptr);
+               "no package rename or extension in configuration projects",
+               Token_Ptr);
          end if;
 
-         --  Scan past "renames"
+         --  Scan past "renames" or "extends"
 
          Scan (In_Tree);
 
@@ -1249,7 +1257,9 @@ 
                end if;
             end if;
          end if;
+      end if;
 
+      if Renaming then
          Expect (Tok_Semicolon, "`;`");
          Set_End_Of_Line (Package_Declaration);
          Set_Previous_Line_Node (Package_Declaration);
@@ -1305,7 +1315,7 @@ 
          Remove_Next_End_Node;
 
       else
-         Error_Msg (Flags, "expected IS or RENAMES", Token_Ptr);
+         Error_Msg (Flags, "expected IS", Token_Ptr);
       end if;
 
    end Parse_Package_Declaration;