Commit 7bc7d27b by Florian Weimer Committed by Florian Weimer

make.adb (Add_Switch): Make Generic_Position a procedure.

2002-07-15  Florian Weimer  <fw@deneb.enyo.de>

	* make.adb (Add_Switch): Make Generic_Position a procedure.  The
	function approach did not work well because of a side effect (the
	function call could reallocate the table which was being indexed
	using its result). Fixes ada/4851. [RESURRECTED]

From-SVN: r55457
parent 1ffa74fb
2002-07-15 Florian Weimer <fw@deneb.enyo.de>
* make.adb (Add_Switch): Make Generic_Position a procedure. The
function approach did not work well because of a side effect (the
function call could reallocate the table which was being indexed
using its result). Fixes ada/4851. [RESURRECTED]
2002-07-01 Roger Sayle <roger@eyesopen.com> 2002-07-01 Roger Sayle <roger@eyesopen.com>
* ada/utils.c (builtin_function): Accept an additional parameter. * ada/utils.c (builtin_function): Accept an additional parameter.
......
...@@ -562,55 +562,61 @@ package body Make is ...@@ -562,55 +562,61 @@ package body Make is
is is
generic generic
with package T is new Table.Table (<>); with package T is new Table.Table (<>);
function Generic_Position return Integer; procedure Generic_Position (New_Position : out Integer);
-- Generic procedure that adds S at the end or beginning of T depending -- Generic procedure that chooses a position for S in T at the
-- of the value of the boolean Append_Switch. -- beginning or the end, depending on the boolean Append_Switch.
---------------------- ----------------------
-- Generic_Position -- -- Generic_Position --
---------------------- ----------------------
function Generic_Position return Integer is procedure Generic_Position (New_Position : out Integer) is
begin begin
T.Increment_Last; T.Increment_Last;
if Append_Switch then if Append_Switch then
return Integer (T.Last); New_Position := Integer (T.Last);
else else
for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
T.Table (J) := T.Table (T.Table_Index_Type'Pred (J)); T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
end loop; end loop;
return Integer (T.First); New_Position := Integer (T.First);
end if; end if;
end Generic_Position; end Generic_Position;
function Gcc_Switches_Pos is new Generic_Position (Gcc_Switches); procedure Gcc_Switches_Pos is new Generic_Position (Gcc_Switches);
function Binder_Switches_Pos is new Generic_Position (Binder_Switches); procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
function Linker_Switches_Pos is new Generic_Position (Linker_Switches); procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
function Saved_Gcc_Switches_Pos is new procedure Saved_Gcc_Switches_Pos is new
Generic_Position (Saved_Gcc_Switches); Generic_Position (Saved_Gcc_Switches);
function Saved_Binder_Switches_Pos is new procedure Saved_Binder_Switches_Pos is new
Generic_Position (Saved_Binder_Switches); Generic_Position (Saved_Binder_Switches);
function Saved_Linker_Switches_Pos is new procedure Saved_Linker_Switches_Pos is new
Generic_Position (Saved_Linker_Switches); Generic_Position (Saved_Linker_Switches);
New_Position : Integer;
-- Start of processing for Add_Switch -- Start of processing for Add_Switch
begin begin
if And_Save then if And_Save then
case Program is case Program is
when Compiler => when Compiler =>
Saved_Gcc_Switches.Table (Saved_Gcc_Switches_Pos) := S; Saved_Gcc_Switches_Pos (New_Position);
Saved_Gcc_Switches.Table (New_Position) := S;
when Binder => when Binder =>
Saved_Binder_Switches.Table (Saved_Binder_Switches_Pos) := S; Saved_Binder_Switches_Pos (New_Position);
Saved_Binder_Switches.Table (New_Position) := S;
when Linker => when Linker =>
Saved_Linker_Switches.Table (Saved_Linker_Switches_Pos) := S; Saved_Linker_Switches_Pos (New_Position);
Saved_Linker_Switches.Table (New_Position) := S;
when None => when None =>
raise Program_Error; raise Program_Error;
...@@ -619,13 +625,16 @@ package body Make is ...@@ -619,13 +625,16 @@ package body Make is
else else
case Program is case Program is
when Compiler => when Compiler =>
Gcc_Switches.Table (Gcc_Switches_Pos) := S; Gcc_Switches_Pos (New_Position);
Gcc_Switches.Table (New_Position) := S;
when Binder => when Binder =>
Binder_Switches.Table (Binder_Switches_Pos) := S; Binder_Switches_Pos (New_Position);
Binder_Switches.Table (New_Position) := S;
when Linker => when Linker =>
Linker_Switches.Table (Linker_Switches_Pos) := S; Linker_Switches_Pos (New_Position);
Linker_Switches.Table (New_Position) := S;
when None => when None =>
raise Program_Error; raise Program_Error;
......
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