summaryrefslogtreecommitdiffstats
path: root/gcc/ada/g-mbdira.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2010-06-22 17:29:41 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2010-06-22 17:29:41 +0000
commit5d9b4687bb8d1a2d2747dcd2ba70631cfb289c8d (patch)
treef457566fb8fc18443973ce2b98d400affc59113c /gcc/ada/g-mbdira.adb
parent1473b207ced691551e6d534710e14193a555323f (diff)
downloadppe42-gcc-5d9b4687bb8d1a2d2747dcd2ba70631cfb289c8d.tar.gz
ppe42-gcc-5d9b4687bb8d1a2d2747dcd2ba70631cfb289c8d.zip
2010-06-22 Robert Dewar <dewar@adacore.com>
* errout.adb (Finalize): Set Prev pointers. (Finalize): Delete continuations for deletion by warnings off(str). * erroutc.ads: Add Prev pointer to error message structure. 2010-06-22 Ed Schonberg <schonberg@adacore.com> * sem.adb (Do_Unit_And_Dependents): If the spec of the main unit is a child unit, examine context of parent units to locate instantiated generics whose bodies may be needed. * sem_ch12.adb: (Mark_Context): if the enclosing unit does not have a with_clause for the instantiated generic, examine the context of its parents, to set Withed_Body flag, so that it can be visited earlier. * exp_ch4.adb (Expand_N_Op_Not): If this is a VMS operator applied to an unsigned type, use a type of the proper size for the intermediate value, to prevent alignment problems on unchecked conversion. 2010-06-22 Geert Bosch <bosch@adacore.com> * s-rannum.ads Change Generator type to be self-referential to allow Random to update its argument. Use "in" mode for the generator in the Reset procedures to allow them to be called from the Ada.Numerics packages without tricks. * s-rannum.adb: Use the self-referencing argument to get write access to the internal state of the random generator. * a-nudira.ads: Make Generator a derived type of System.Random_Numbers.Generator. * a-nudira.adb: Remove use of 'Unrestricted_Access. Put subprograms in alpha order and add headers. * g-mbdira.ads: Change Generator type to be self-referential. * g-mbdira.adb: Remove use of 'Unrestricted_Access. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161215 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-mbdira.adb')
-rw-r--r--gcc/ada/g-mbdira.adb42
1 files changed, 12 insertions, 30 deletions
diff --git a/gcc/ada/g-mbdira.adb b/gcc/ada/g-mbdira.adb
index e7e1c470d67..f5fd4dce60d 100644
--- a/gcc/ada/g-mbdira.adb
+++ b/gcc/ada/g-mbdira.adb
@@ -35,25 +35,8 @@ with Interfaces; use Interfaces;
package body GNAT.MBBS_Discrete_Random is
- -------------------------
- -- Implementation Note --
- -------------------------
-
- -- The design of this spec is a bit awkward, as a result of Ada 95 not
- -- permitting in-out parameters for function formals (most naturally
- -- Generator values would be passed this way). In pure Ada 95, the only
- -- solution would be to add a self-referential component to the generator
- -- allowing access to the generator object from inside the function. This
- -- would work because the generator is limited, which prevents any copy.
-
- -- This is a bit heavy, so what we do is to use Unrestricted_Access to
- -- get a pointer to the state in the passed Generator. This works because
- -- Generator is a limited type and will thus always be passed by reference.
-
package Calendar renames Ada.Calendar;
- type Pointer is access all State;
-
Fits_In_32_Bits : constant Boolean :=
Rst'Size < 31
or else (Rst'Size = 31
@@ -109,7 +92,7 @@ package body GNAT.MBBS_Discrete_Random is
------------
function Random (Gen : Generator) return Rst is
- Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
+ S : State renames Gen.Writable.Self.Gen_State;
Temp : Int;
TF : Flt;
@@ -124,21 +107,21 @@ package body GNAT.MBBS_Discrete_Random is
-- Continue with computation if non-flat range
- Genp.X1 := Square_Mod_N (Genp.X1, Genp.P);
- Genp.X2 := Square_Mod_N (Genp.X2, Genp.Q);
- Temp := Genp.X2 - Genp.X1;
+ S.X1 := Square_Mod_N (S.X1, S.P);
+ S.X2 := Square_Mod_N (S.X2, S.Q);
+ Temp := S.X2 - S.X1;
-- Following duplication is not an error, it is a loop unwinding!
if Temp < 0 then
- Temp := Temp + Genp.Q;
+ Temp := Temp + S.Q;
end if;
if Temp < 0 then
- Temp := Temp + Genp.Q;
+ Temp := Temp + S.Q;
end if;
- TF := Offs + (Flt (Temp) * Flt (Genp.P) + Flt (Genp.X1)) * Genp.Scl;
+ TF := Offs + (Flt (Temp) * Flt (S.P) + Flt (S.X1)) * S.Scl;
-- Pathological, but there do exist cases where the rounding implicit
-- in calculating the scale factor will cause rounding to 'Last + 1.
@@ -160,7 +143,7 @@ package body GNAT.MBBS_Discrete_Random is
-----------
procedure Reset (Gen : Generator; Initiator : Integer) is
- Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
+ S : State renames Gen.Writable.Self.Gen_State;
X1, X2 : Int;
begin
@@ -174,7 +157,7 @@ package body GNAT.MBBS_Discrete_Random is
-- Eliminate effects of small Initiators
- Genp.all :=
+ S :=
(X1 => X1,
X2 => X2,
P => K1,
@@ -188,7 +171,7 @@ package body GNAT.MBBS_Discrete_Random is
-----------
procedure Reset (Gen : Generator) is
- Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
+ S : State renames Gen.Writable.Self.Gen_State;
Now : constant Calendar.Time := Calendar.Clock;
X1 : Int;
X2 : Int;
@@ -210,7 +193,7 @@ package body GNAT.MBBS_Discrete_Random is
X2 := Square_Mod_N (X2, K2);
end loop;
- Genp.all :=
+ S :=
(X1 => X1,
X2 => X2,
P => K1,
@@ -225,9 +208,8 @@ package body GNAT.MBBS_Discrete_Random is
-----------
procedure Reset (Gen : Generator; From_State : State) is
- Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
begin
- Genp.all := From_State;
+ Gen.Writable.Self.Gen_State := From_State;
end Reset;
----------
OpenPOWER on IntegriCloud