From patchwork Tue Oct 5 10:08:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Allow wild cards in Switches () in project files Date: Tue, 05 Oct 2010 00:08:58 -0000 From: Arnaud Charlet X-Patchwork-Id: 66787 Message-Id: <20101005100858.GA31202@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Vincent Celier Wild cards ('*' and '?') are now recognized in attribute Switches in packages Compiler, Binder and Linker in project files. If there are 3 sources: main.adb, pkg.ads and pkg-child.ads for the following project file: project Prj is for Main use ("main.adb"); package Compiler is for Switches ("pkg*") use ("-O2"); end Compiler; end Prj; sources pkg.ads and pkg-child.ads should be compiled with -O2. Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-05 Vincent Celier * make.adb (Switches_Of): Allow wild cards in index of attributes Switches. * prj-util.adb (Value_Of): When Allow_Wildcards is True, use the index of the associative array as a glob regular expression. * prj-util.ads (Value_Of (Index, In_Array)): New Boolean parameter Allow_Wildcards, defaulted to False. (Value_Of (Name, Attribute_Or_Array_Name)): Ditto * projects.texi: Document that attribute Switches () may use wild cards in the index. Index: make.adb =================================================================== --- make.adb (revision 164975) +++ make.adb (working copy) @@ -8361,10 +8361,11 @@ package body Make is Switches := Prj.Util.Value_Of - (Index => Name_Id (Source_File), - Src_Index => Source_Index, - In_Array => Switches_Array, - In_Tree => Project_Tree); + (Index => Name_Id (Source_File), + Src_Index => Source_Index, + In_Array => Switches_Array, + In_Tree => Project_Tree, + Allow_Wildcards => True); -- Check also without the suffix @@ -8406,10 +8407,11 @@ package body Make is Add_Str_To_Name_Buffer (Name (1 .. Last)); Switches := Prj.Util.Value_Of - (Index => Name_Find, - Src_Index => 0, - In_Array => Switches_Array, - In_Tree => Project_Tree); + (Index => Name_Find, + Src_Index => 0, + In_Array => Switches_Array, + In_Tree => Project_Tree, + Allow_Wildcards => True); if Switches = Nil_Variable_Value and then Allow_ALI then Last := Source_File_Name'Length; Index: prj-util.adb =================================================================== --- prj-util.adb (revision 164975) +++ prj-util.adb (working copy) @@ -26,6 +26,7 @@ with Ada.Unchecked_Deallocation; with GNAT.Case_Util; use GNAT.Case_Util; +with GNAT.Regexp; use GNAT.Regexp; with Osint; use Osint; with Output; use Output; @@ -848,7 +849,8 @@ package body Prj.Util is Src_Index : Int := 0; In_Array : Array_Element_Id; In_Tree : Project_Tree_Ref; - Force_Lower_Case_Index : Boolean := False) return Variable_Value + Force_Lower_Case_Index : Boolean := False; + Allow_Wildcards : Boolean := False) return Variable_Value is Current : Array_Element_Id; Element : Array_Element; @@ -888,8 +890,13 @@ package body Prj.Util is end if; end if; - if Real_Index_1 = Real_Index_2 and then - Src_Index = Element.Src_Index + if Src_Index = Element.Src_Index and then + (Real_Index_1 = Real_Index_2 or else + (Real_Index_2 /= All_Other_Names and then + Allow_Wildcards and then + Match (Get_Name_String (Real_Index_1), + Compile (Get_Name_String (Real_Index_2), + Glob => True)))) then return Element.Value; else @@ -906,7 +913,8 @@ package body Prj.Util is Attribute_Or_Array_Name : Name_Id; In_Package : Package_Id; In_Tree : Project_Tree_Ref; - Force_Lower_Case_Index : Boolean := False) return Variable_Value + Force_Lower_Case_Index : Boolean := False; + Allow_Wildcards : Boolean := False) return Variable_Value is The_Array : Array_Element_Id; The_Attribute : Variable_Value := Nil_Variable_Value; @@ -927,7 +935,8 @@ package body Prj.Util is Src_Index => Index, In_Array => The_Array, In_Tree => In_Tree, - Force_Lower_Case_Index => Force_Lower_Case_Index); + Force_Lower_Case_Index => Force_Lower_Case_Index, + Allow_Wildcards => Allow_Wildcards); -- If there is no array element, look for a variable Index: prj-util.ads =================================================================== --- prj-util.ads (revision 164975) +++ prj-util.ads (working copy) @@ -86,7 +86,8 @@ package Prj.Util is Src_Index : Int := 0; In_Array : Array_Element_Id; In_Tree : Project_Tree_Ref; - Force_Lower_Case_Index : Boolean := False) return Variable_Value; + Force_Lower_Case_Index : Boolean := False; + Allow_Wildcards : Boolean := False) return Variable_Value; -- Get a string array component (single String or String list). Returns -- Nil_Variable_Value if no component Index or if In_Array is null. -- @@ -101,7 +102,8 @@ package Prj.Util is Attribute_Or_Array_Name : Name_Id; In_Package : Package_Id; In_Tree : Project_Tree_Ref; - Force_Lower_Case_Index : Boolean := False) return Variable_Value; + Force_Lower_Case_Index : Boolean := False; + Allow_Wildcards : Boolean := False) return Variable_Value; -- In a specific package, -- - if there exists an array Attribute_Or_Array_Name with an index Name, -- returns the corresponding component (depending on the attribute, the Index: projects.texi =================================================================== --- projects.texi (revision 164906) +++ projects.texi (working copy) @@ -633,8 +633,23 @@ Several attributes can be used to specif @end smallexample @noindent + @code{Switches} may take a pattern as an index, such as in: + + @smallexample + @b{package} Compiler @b{is} + @b{for} Default_Switches ("Ada") @b{use} ("-O2"); + @b{for} Switches ("pkg*") @b{use} ("-O0"); + @b{end} Compiler; + @end smallexample + + @noindent + Sources @file{pkg.adb} and @file{pkg-child.adb} would be compiled with -O0, + not -O2. + + @noindent @code{Switches} can also be given a language name as index instead of a file name in which case it has the same semantics as @emph{Default_Switches}. + However, indexes with wild cards are never valid for language name. @item @b{Local_Configuration_Pragmas}: @cindex @code{Local_Configuration_Pragmas}