Commit 6a1cb33a by Bob Duff Committed by Arnaud Charlet

clean.adb (Usage): Add line for -aP

2007-12-06  Bob Duff  <duff@adacore.com>

	* clean.adb (Usage): Add line for -aP
	(Check_Version_And_Help): Change Check_Version_And_Help to be generic,
	with a parameter "procedure Usage", instead of passing a pointer to a
	procedure. This is to eliminate trampolines (since the Usage procedure
	is often nested in a main procedure, and it would be inconvenient to
	unnest it).

	* g-comlin.adb (For_Each_Simple_Switch): Change For_Each_Simple_Switch
	to be generic, with a parameter "procedure Callback (...)", instead of
	passing a pointer to a procedure. This is to eliminate trampolines
	(since the Callback procedure is usually nested).

	* gnatfind.adb, switch.adb, switch.ads, gnatlink.adb, gnatls.adb, 
	gnatname.adb, gnatxref.adb, gnatchop.adb, gprep.adb, gnatbind.adb
	(Check_Version_And_Help): Change Check_Version_And_Help to be generic.

	* g-pehage.adb (Compute_Edges_And_Vertices, Build_Identical_Key_Sets):
	Use the generic Heap_Sort_G instead of Heap_Sort_A.

From-SVN: r130824
parent 16a55e63
...@@ -1637,10 +1637,12 @@ package body Clean is ...@@ -1637,10 +1637,12 @@ package body Clean is
Source_Index : Int := 0; Source_Index : Int := 0;
Index : Positive; Index : Positive;
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
begin begin
-- First, check for --version and --help -- First, check for --version and --help
Check_Version_And_Help ("GNATCLEAN", "2003", Usage'Access); Check_Version_And_Help ("GNATCLEAN", "2003");
Index := 1; Index := 1;
while Index <= Last loop while Index <= Last loop
...@@ -1970,6 +1972,9 @@ package body Clean is ...@@ -1970,6 +1972,9 @@ package body Clean is
"for GNAT Project Files"); "for GNAT Project Files");
New_Line; New_Line;
Put_Line (" -aPdir Add directory dir to project search path");
New_Line;
Put_Line (" -aOdir Specify ALI/object files search path"); Put_Line (" -aOdir Specify ALI/object files search path");
Put_Line (" -Idir Like -aOdir"); Put_Line (" -Idir Like -aOdir");
Put_Line (" -I- Don't look for source/library files " & Put_Line (" -I- Don't look for source/library files " &
......
...@@ -114,11 +114,11 @@ package body GNAT.Command_Line is ...@@ -114,11 +114,11 @@ package body GNAT.Command_Line is
function Args_From_Expanded (Args : Boolean_Chars) return String; function Args_From_Expanded (Args : Boolean_Chars) return String;
-- Return the string made of all characters with True in Args -- Return the string made of all characters with True in Args
type Callback_Procedure is access procedure (Simple_Switch : String); generic
with procedure Callback (Simple_Switch : String);
procedure For_Each_Simple_Switch procedure For_Each_Simple_Switch
(Cmd : Command_Line; (Cmd : Command_Line;
Switch : String; Switch : String);
Callback : Callback_Procedure);
-- Breaks Switch into as simple switches as possible (expanding aliases and -- Breaks Switch into as simple switches as possible (expanding aliases and
-- ungrouping common prefixes when possible), and call Callback for each of -- ungrouping common prefixes when possible), and call Callback for each of
-- these. -- these.
...@@ -1185,9 +1185,8 @@ package body GNAT.Command_Line is ...@@ -1185,9 +1185,8 @@ package body GNAT.Command_Line is
---------------------------- ----------------------------
procedure For_Each_Simple_Switch procedure For_Each_Simple_Switch
(Cmd : Command_Line; (Cmd : Command_Line;
Switch : String; Switch : String)
Callback : Callback_Procedure)
is is
begin begin
-- Are we adding a switch that can in fact be expanded through aliases ? -- Are we adding a switch that can in fact be expanded through aliases ?
...@@ -1204,7 +1203,7 @@ package body GNAT.Command_Line is ...@@ -1204,7 +1203,7 @@ package body GNAT.Command_Line is
for A in Cmd.Config.Aliases'Range loop for A in Cmd.Config.Aliases'Range loop
if Cmd.Config.Aliases (A).all = Switch then if Cmd.Config.Aliases (A).all = Switch then
For_Each_Simple_Switch For_Each_Simple_Switch
(Cmd, Cmd.Config.Expansions (A).all, Callback); (Cmd, Cmd.Config.Expansions (A).all);
return; return;
end if; end if;
end loop; end loop;
...@@ -1227,7 +1226,7 @@ package body GNAT.Command_Line is ...@@ -1227,7 +1226,7 @@ package body GNAT.Command_Line is
.. Switch'Last .. Switch'Last
loop loop
For_Each_Simple_Switch For_Each_Simple_Switch
(Cmd, Cmd.Config.Prefixes (P).all & Switch (S), Callback); (Cmd, Cmd.Config.Prefixes (P).all & Switch (S));
end loop; end loop;
return; return;
end if; end if;
...@@ -1291,11 +1290,13 @@ package body GNAT.Command_Line is ...@@ -1291,11 +1290,13 @@ package body GNAT.Command_Line is
end if; end if;
end Add_Simple_Switch; end Add_Simple_Switch;
procedure Add_Simple_Switches is
new For_Each_Simple_Switch (Add_Simple_Switch);
-- Start of processing for Add_Switch -- Start of processing for Add_Switch
begin begin
For_Each_Simple_Switch Add_Simple_Switches (Cmd, Switch);
(Cmd, Switch, Add_Simple_Switch'Unrestricted_Access);
Free (Cmd.Coalesce); Free (Cmd.Coalesce);
end Add_Switch; end Add_Switch;
...@@ -1381,11 +1382,13 @@ package body GNAT.Command_Line is ...@@ -1381,11 +1382,13 @@ package body GNAT.Command_Line is
end if; end if;
end Remove_Simple_Switch; end Remove_Simple_Switch;
procedure Remove_Simple_Switches is
new For_Each_Simple_Switch (Remove_Simple_Switch);
-- Start of processing for Remove_Switch -- Start of processing for Remove_Switch
begin begin
For_Each_Simple_Switch Remove_Simple_Switches (Cmd, Switch);
(Cmd, Switch, Remove_Simple_Switch'Unrestricted_Access);
Free (Cmd.Coalesce); Free (Cmd.Coalesce);
end Remove_Switch; end Remove_Switch;
...@@ -1440,11 +1443,13 @@ package body GNAT.Command_Line is ...@@ -1440,11 +1443,13 @@ package body GNAT.Command_Line is
end if; end if;
end Remove_Simple_Switch; end Remove_Simple_Switch;
procedure Remove_Simple_Switches is
new For_Each_Simple_Switch (Remove_Simple_Switch);
-- Start of processing for Remove_Switch -- Start of processing for Remove_Switch
begin begin
For_Each_Simple_Switch Remove_Simple_Switches (Cmd, Switch);
(Cmd, Switch, Remove_Simple_Switch'Unrestricted_Access);
Free (Cmd.Coalesce); Free (Cmd.Coalesce);
end Remove_Switch; end Remove_Switch;
...@@ -1566,6 +1571,9 @@ package body GNAT.Command_Line is ...@@ -1566,6 +1571,9 @@ package body GNAT.Command_Line is
end loop; end loop;
end Remove_Cb; end Remove_Cb;
procedure Check_All is new For_Each_Simple_Switch (Check_Cb);
procedure Remove_All is new For_Each_Simple_Switch (Remove_Cb);
-- Start of processing for Alias_Switches -- Start of processing for Alias_Switches
begin begin
...@@ -1582,15 +1590,11 @@ package body GNAT.Command_Line is ...@@ -1582,15 +1590,11 @@ package body GNAT.Command_Line is
-- then check whether the expanded command line has all of them. -- then check whether the expanded command line has all of them.
Found := True; Found := True;
For_Each_Simple_Switch Check_All (Cmd, Cmd.Config.Expansions (A).all);
(Cmd, Cmd.Config.Expansions (A).all,
Check_Cb'Unrestricted_Access);
if Found then if Found then
First := Integer'Last; First := Integer'Last;
For_Each_Simple_Switch Remove_All (Cmd, Cmd.Config.Expansions (A).all);
(Cmd, Cmd.Config.Expansions (A).all,
Remove_Cb'Unrestricted_Access);
Result (First) := new String'(Cmd.Config.Aliases (A).all); Result (First) := new String'(Cmd.Config.Aliases (A).all);
end if; end if;
end loop; end loop;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
with Ada.Exceptions; use Ada.Exceptions; with Ada.Exceptions; use Ada.Exceptions;
with Ada.IO_Exceptions; use Ada.IO_Exceptions; with Ada.IO_Exceptions; use Ada.IO_Exceptions;
with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A; with GNAT.Heap_Sort_G;
with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Table; with GNAT.Table;
...@@ -696,7 +696,7 @@ package body GNAT.Perfect_Hash_Generators is ...@@ -696,7 +696,7 @@ package body GNAT.Perfect_Hash_Generators is
procedure Move (From : Natural; To : Natural); procedure Move (From : Natural; To : Natural);
function Lt (L, R : Natural) return Boolean; function Lt (L, R : Natural) return Boolean;
-- Subprograms needed for GNAT.Heap_Sort_A -- Subprograms needed for GNAT.Heap_Sort_G
-------- --------
-- Lt -- -- Lt --
...@@ -718,11 +718,13 @@ package body GNAT.Perfect_Hash_Generators is ...@@ -718,11 +718,13 @@ package body GNAT.Perfect_Hash_Generators is
Set_Edges (To, Get_Edges (From)); Set_Edges (To, Get_Edges (From));
end Move; end Move;
package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
-- Start of processing for Compute_Edges_And_Vertices -- Start of processing for Compute_Edges_And_Vertices
begin begin
-- We store edges from 1 to 2 * NK and leave zero alone in order to use -- We store edges from 1 to 2 * NK and leave zero alone in order to use
-- GNAT.Heap_Sort_A. -- GNAT.Heap_Sort_G.
Edges_Len := 2 * NK + 1; Edges_Len := 2 * NK + 1;
...@@ -780,10 +782,7 @@ package body GNAT.Perfect_Hash_Generators is ...@@ -780,10 +782,7 @@ package body GNAT.Perfect_Hash_Generators is
-- is sorted by X and then Y. To compute the neighbor list, sort the -- is sorted by X and then Y. To compute the neighbor list, sort the
-- edges. -- edges.
Sort Sorting.Sort (Edges_Len - 1);
(Edges_Len - 1,
Move'Unrestricted_Access,
Lt'Unrestricted_Access);
if Verbose then if Verbose then
Put_Edges (Output, "Sorted Edge Table"); Put_Edges (Output, "Sorted Edge Table");
...@@ -1976,7 +1975,7 @@ package body GNAT.Perfect_Hash_Generators is ...@@ -1976,7 +1975,7 @@ package body GNAT.Perfect_Hash_Generators is
function Lt (L, R : Natural) return Boolean; function Lt (L, R : Natural) return Boolean;
procedure Move (From : Natural; To : Natural); procedure Move (From : Natural; To : Natural);
-- Subprograms needed by GNAT.Heap_Sort_A -- Subprograms needed by GNAT.Heap_Sort_G
-------- --------
-- Lt -- -- Lt --
...@@ -2024,6 +2023,8 @@ package body GNAT.Perfect_Hash_Generators is ...@@ -2024,6 +2023,8 @@ package body GNAT.Perfect_Hash_Generators is
WT.Table (Target) := WT.Table (Source); WT.Table (Target) := WT.Table (Source);
end Move; end Move;
package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
-- Start of processing for Build_Identical_Key_Sets -- Start of processing for Build_Identical_Key_Sets
begin begin
...@@ -2041,10 +2042,7 @@ package body GNAT.Perfect_Hash_Generators is ...@@ -2041,10 +2042,7 @@ package body GNAT.Perfect_Hash_Generators is
else else
Offset := Reduced (S (J).First) - 1; Offset := Reduced (S (J).First) - 1;
Sort Sorting.Sort (S (J).Last - S (J).First + 1);
(S (J).Last - S (J).First + 1,
Move'Unrestricted_Access,
Lt'Unrestricted_Access);
F := S (J).First; F := S (J).First;
L := F; L := F;
......
...@@ -403,6 +403,9 @@ procedure Gnatbind is ...@@ -403,6 +403,9 @@ procedure Gnatbind is
end if; end if;
end Scan_Bind_Arg; end Scan_Bind_Arg;
procedure Check_Version_And_Help is
new Check_Version_And_Help_G (Bindusg.Display);
-- Start of processing for Gnatbind -- Start of processing for Gnatbind
begin begin
...@@ -429,7 +432,7 @@ begin ...@@ -429,7 +432,7 @@ begin
-- First, scan to detect --version and/or --help -- First, scan to detect --version and/or --help
Check_Version_And_Help ("GNATBIND", "1995", Bindusg.Display'Access); Check_Version_And_Help ("GNATBIND", "1995");
-- Use low level argument routines to avoid dragging in the secondary stack -- Use low level argument routines to avoid dragging in the secondary stack
......
...@@ -1724,6 +1724,8 @@ procedure Gnatchop is ...@@ -1724,6 +1724,8 @@ procedure Gnatchop is
end; end;
end Write_Unit; end Write_Unit;
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for gnatchop -- Start of processing for gnatchop
begin begin
...@@ -1763,7 +1765,7 @@ begin ...@@ -1763,7 +1765,7 @@ begin
-- First, scan to detect --version and/or --help -- First, scan to detect --version and/or --help
Check_Version_And_Help ("GNATCHOP", "1998", Usage'Unrestricted_Access); Check_Version_And_Help ("GNATCHOP", "1998");
if not Scan_Arguments then if not Scan_Arguments then
Set_Exit_Status (Failure); Set_Exit_Status (Failure);
......
...@@ -78,10 +78,15 @@ procedure Gnatfind is ...@@ -78,10 +78,15 @@ procedure Gnatfind is
-------------------- --------------------
procedure Parse_Cmd_Line is procedure Parse_Cmd_Line is
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for Parse_Cmd_Line
begin begin
-- First check for --version or --help -- First check for --version or --help
Check_Version_And_Help ("GNATFIND", "1998", Usage'Unrestricted_Access); Check_Version_And_Help ("GNATFIND", "1998");
-- Now scan the other switches -- Now scan the other switches
......
...@@ -292,10 +292,14 @@ procedure Gnatlink is ...@@ -292,10 +292,14 @@ procedure Gnatlink is
-- Set to true if the next argument is to be added into the list of -- Set to true if the next argument is to be added into the list of
-- linker's argument without parsing it. -- linker's argument without parsing it.
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for Process_Args
begin begin
-- First, check for --version and --help -- First, check for --version and --help
Check_Version_And_Help ("GNATLINK", "1995", Usage'Unrestricted_Access); Check_Version_And_Help ("GNATLINK", "1995");
-- Loop through arguments of gnatlink command -- Loop through arguments of gnatlink command
...@@ -1765,7 +1769,12 @@ begin ...@@ -1765,7 +1769,12 @@ begin
Binder_Options.Table (J); Binder_Options.Table (J);
end loop; end loop;
Args (Args'Last) := Binder_Body_Src_File; -- Use the full path of the binder generated source, so that it is
-- guaranteed that the debugger will find this source, even with
-- STABS.
Args (Args'Last) :=
new String'(Normalize_Pathname (Binder_Body_Src_File.all));
if Verbose_Mode then if Verbose_Mode then
Write_Str (Base_Name (Gcc_Path.all)); Write_Str (Base_Name (Gcc_Path.all));
......
...@@ -1519,6 +1519,8 @@ procedure Gnatls is ...@@ -1519,6 +1519,8 @@ procedure Gnatls is
end loop; end loop;
end Usage; end Usage;
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for Gnatls -- Start of processing for Gnatls
begin begin
...@@ -1530,7 +1532,7 @@ begin ...@@ -1530,7 +1532,7 @@ begin
-- First check for --version or --help -- First check for --version or --help
Check_Version_And_Help ("GNATLS", "1997", Usage'Unrestricted_Access); Check_Version_And_Help ("GNATLS", "1997");
-- Loop to scan out arguments -- Loop to scan out arguments
......
...@@ -177,10 +177,15 @@ procedure Gnatname is ...@@ -177,10 +177,15 @@ procedure Gnatname is
--------------- ---------------
procedure Scan_Args is procedure Scan_Args is
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for Scan_Args
begin begin
-- First check for --version or --help -- First check for --version or --help
Check_Version_And_Help ("GNATNAME", "2001", Usage'Unrestricted_Access); Check_Version_And_Help ("GNATNAME", "2001");
-- Now scan the other switches -- Now scan the other switches
......
...@@ -66,10 +66,15 @@ procedure Gnatxref is ...@@ -66,10 +66,15 @@ procedure Gnatxref is
-------------------- --------------------
procedure Parse_Cmd_Line is procedure Parse_Cmd_Line is
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for Parse_Cmd_Line
begin begin
-- First check for --version or --help -- First check for --version or --help
Check_Version_And_Help ("GNATXREF", "1998", Usage'Unrestricted_Access); Check_Version_And_Help ("GNATXREF", "1998");
loop loop
case case
......
...@@ -699,10 +699,14 @@ package body GPrep is ...@@ -699,10 +699,14 @@ package body GPrep is
procedure Scan_Command_Line is procedure Scan_Command_Line is
Switch : Character; Switch : Character;
procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
-- Start of processing for Scan_Command_Line
begin begin
-- First check for --version or --help -- First check for --version or --help
Check_Version_And_Help ("GNATPREP", "1996", Usage'Access); Check_Version_And_Help ("GNATPREP", "1996");
-- Now scan the other switches -- Now scan the other switches
......
...@@ -42,14 +42,13 @@ package body Switch is ...@@ -42,14 +42,13 @@ package body Switch is
Osint.Fail ("invalid switch: ", Switch); Osint.Fail ("invalid switch: ", Switch);
end Bad_Switch; end Bad_Switch;
---------------------------- ------------------------------
-- Check_Version_And_Help -- -- Check_Version_And_Help_G --
---------------------------- ------------------------------
procedure Check_Version_And_Help procedure Check_Version_And_Help_G
(Tool_Name : String; (Tool_Name : String;
Initial_Year : String; Initial_Year : String;
Usage : Procedure_Ptr;
Version_String : String := Gnatvsn.Gnat_Version_String) Version_String : String := Gnatvsn.Gnat_Version_String)
is is
Version_Switch_Present : Boolean := False; Version_Switch_Present : Boolean := False;
...@@ -92,12 +91,12 @@ package body Switch is ...@@ -92,12 +91,12 @@ package body Switch is
if Help_Switch_Present then if Help_Switch_Present then
Set_Standard_Output; Set_Standard_Output;
Usage.all; Usage;
Write_Eol; Write_Eol;
Write_Line ("Report bugs to report@adacore.com"); Write_Line ("Report bugs to report@adacore.com");
Exit_Program (E_Success); Exit_Program (E_Success);
end if; end if;
end Check_Version_And_Help; end Check_Version_And_Help_G;
--------------------- ---------------------
-- Display_Version -- -- Display_Version --
......
...@@ -23,16 +23,20 @@ ...@@ -23,16 +23,20 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- This package together with a child package appropriate to the client -- This package together with a child package appropriate to the client tool
-- tool scans switches. Note that the body of the appropraite Usage package -- scans switches. Note that the body of the appropraite Usage package must be
-- must be coordinated with the switches that are recognized by this package. -- coordinated with the switches that are recognized by this package. These
-- These Usage packages also act as the official documentation for the -- Usage packages also act as the official documentation for the switches
-- switches that are recognized. In addition, package Debug documents -- that are recognized. In addition, package Debug documents the otherwise
-- the otherwise undocumented debug switches that are also recognized. -- undocumented debug switches that are also recognized.
with Gnatvsn; with Gnatvsn;
with Types; use Types; with Types; use Types;
------------
-- Switch --
------------
package Switch is package Switch is
-- Common switches for GNU tools -- Common switches for GNU tools
...@@ -44,15 +48,15 @@ package Switch is ...@@ -44,15 +48,15 @@ package Switch is
-- Subprograms -- -- Subprograms --
----------------- -----------------
type Procedure_Ptr is access procedure; generic
with procedure Usage;
procedure Check_Version_And_Help -- Print tool-specific part of --help message
procedure Check_Version_And_Help_G
(Tool_Name : String; (Tool_Name : String;
Initial_Year : String; Initial_Year : String;
Usage : Procedure_Ptr;
Version_String : String := Gnatvsn.Gnat_Version_String); Version_String : String := Gnatvsn.Gnat_Version_String);
-- Check if switches --version or --help is used. If one of this switch -- Check if switches --version or --help is used. If one of this switch is
-- is used, issue the proper messages and end the process. -- used, issue the proper messages and end the process.
procedure Display_Version procedure Display_Version
(Tool_Name : String; (Tool_Name : String;
...@@ -61,12 +65,12 @@ package Switch is ...@@ -61,12 +65,12 @@ package Switch is
-- Display version of a tool when switch --version is used -- Display version of a tool when switch --version is used
function Is_Switch (Switch_Chars : String) return Boolean; function Is_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars is at least two characters long, -- Returns True iff Switch_Chars is at least two characters long, and the
-- and the first character is an hyphen ('-'). -- first character is an hyphen ('-').
function Is_Front_End_Switch (Switch_Chars : String) return Boolean; function Is_Front_End_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars represents a front-end switch, -- Returns True iff Switch_Chars represents a front-end switch, i.e. it
-- ie. it starts with -I, -gnat or -?RTS. -- starts with -I, -gnat or -?RTS.
private private
...@@ -83,9 +87,9 @@ private ...@@ -83,9 +87,9 @@ private
Ptr : in out Integer; Ptr : in out Integer;
Result : out Nat; Result : out Nat;
Switch : Character); Switch : Character);
-- Scan natural integer parameter for switch. On entry, Ptr points -- Scan natural integer parameter for switch. On entry, Ptr points just
-- just past the switch character, on exit it points past the last -- past the switch character, on exit it points past the last digit of the
-- digit of the integer value. -- integer value.
procedure Scan_Pos procedure Scan_Pos
(Switch_Chars : String; (Switch_Chars : String;
...@@ -93,9 +97,9 @@ private ...@@ -93,9 +97,9 @@ private
Ptr : in out Integer; Ptr : in out Integer;
Result : out Pos; Result : out Pos;
Switch : Character); Switch : Character);
-- Scan positive integer parameter for switch. On entry, Ptr points -- Scan positive integer parameter for switch. On entry, Ptr points just
-- just past the switch character, on exit it points past the last -- past the switch character, on exit it points past the last digit of the
-- digit of the integer value. -- integer value.
procedure Bad_Switch (Switch : Character); procedure Bad_Switch (Switch : Character);
procedure Bad_Switch (Switch : String); procedure Bad_Switch (Switch : String);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment