From 1c612f29199ea74e57bd9872e11ee726703aab2f Mon Sep 17 00:00:00 2001 From: Robert Dewar Date: Tue, 22 Jun 2010 15:32:18 +0000 Subject: [PATCH] s-rannum.adb, [...]: Minor reformatting. 2010-06-22 Robert Dewar * s-rannum.adb, a-nudira.adb, types.ads, freeze.adb, sem_aggr.adb, exp_aggr.adb: Minor reformatting. * gnat_rm.texi: Document GNAT.MBBS_Discrete_Random and GNAT.MBSS_Float_Random. * g-mbdira.adb, g-mbflra.adb, g-mbdira.ads, g-mbflra.ads: Fix header. From-SVN: r161194 --- gcc/ada/ChangeLog | 8 +++++++ gcc/ada/a-nudira.adb | 22 ++++++++++++------- gcc/ada/exp_aggr.adb | 30 +++++++++++++------------- gcc/ada/freeze.adb | 8 +++---- gcc/ada/g-mbdira.adb | 2 +- gcc/ada/g-mbdira.ads | 2 +- gcc/ada/g-mbflra.adb | 2 +- gcc/ada/g-mbflra.ads | 2 +- gcc/ada/gnat_rm.texi | 22 +++++++++++++++++++ gcc/ada/s-rannum.adb | 51 ++++++++++++++++++++++---------------------- gcc/ada/sem_aggr.adb | 4 ++-- gcc/ada/types.ads | 8 +++---- 12 files changed, 99 insertions(+), 62 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 700fa324ac2..b80c597834f 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2010-06-22 Robert Dewar + + * s-rannum.adb, a-nudira.adb, types.ads, freeze.adb, sem_aggr.adb, + exp_aggr.adb: Minor reformatting. + * gnat_rm.texi: Document GNAT.MBBS_Discrete_Random and + GNAT.MBSS_Float_Random. + * g-mbdira.adb, g-mbflra.adb, g-mbdira.ads, g-mbflra.ads: Fix header. + 2010-06-22 Paul Hilfinger * a-nudira.adb, a-nudira.ads, a-nuflra.adb, a-nuflra.ads, diff --git a/gcc/ada/a-nudira.adb b/gcc/ada/a-nudira.adb index e17945c07a2..b8a31274550 100644 --- a/gcc/ada/a-nudira.adb +++ b/gcc/ada/a-nudira.adb @@ -58,33 +58,39 @@ package body Ada.Numerics.Discrete_Random is return Rep_Random (Gen.Rep); end Random; - procedure Reset (Gen : Generator; - Initiator : Integer) is + procedure Reset + (Gen : Generator; + Initiator : Integer) + is G : Rep_Generator renames Gen.Rep'Unrestricted_Access.all; begin Reset (G, Initiator); end Reset; - procedure Reset (Gen : Generator) is + procedure Reset (Gen : Generator) is G : Rep_Generator renames Gen.Rep'Unrestricted_Access.all; begin Reset (G); end Reset; - procedure Save (Gen : Generator; - To_State : out State) is + procedure Save + (Gen : Generator; + To_State : out State) + is begin Save (Gen.Rep, State (To_State)); end Save; - procedure Reset (Gen : Generator; - From_State : State) is + procedure Reset + (Gen : Generator; + From_State : State) + is G : Rep_Generator renames Gen.Rep'Unrestricted_Access.all; begin Reset (G, From_State); end Reset; - function Image (Of_State : State) return String is + function Image (Of_State : State) return String is begin return Image (Rep_State (Of_State)); end Image; diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 9345da2f56b..c4e3b01c7a1 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -2861,14 +2861,14 @@ package body Exp_Aggr is if Is_CPP_Constructor_Call (Expression (Comp)) then Append_List_To (L, Build_Initialization_Call (Loc, - Id_Ref => Make_Selected_Component (Loc, - Prefix => New_Copy_Tree (Target), - Selector_Name => New_Occurrence_Of (Selector, - Loc)), - Typ => Etype (Selector), - Enclos_Type => Typ, + Id_Ref => Make_Selected_Component (Loc, + Prefix => New_Copy_Tree (Target), + Selector_Name => + New_Occurrence_Of (Selector, Loc)), + Typ => Etype (Selector), + Enclos_Type => Typ, With_Default_Init => True, - Constructor_Ref => Expression (Comp))); + Constructor_Ref => Expression (Comp))); -- Ada 2005 (AI-287): For each default-initialized component generate -- a call to the corresponding IP subprogram if available. @@ -2887,8 +2887,8 @@ package body Exp_Aggr is declare Ctype : constant Entity_Id := Etype (Selector); - Inside_Allocator : Boolean := False; - P : Node_Id := Parent (N); + Inside_Allocator : Boolean := False; + P : Node_Id := Parent (N); begin if Is_Task_Type (Ctype) or else Has_Task (Ctype) then @@ -2909,12 +2909,12 @@ package body Exp_Aggr is Append_List_To (L, Build_Initialization_Call (Loc, - Id_Ref => Make_Selected_Component (Loc, - Prefix => New_Copy_Tree (Target), - Selector_Name => New_Occurrence_Of (Selector, - Loc)), - Typ => Etype (Selector), - Enclos_Type => Typ, + Id_Ref => Make_Selected_Component (Loc, + Prefix => New_Copy_Tree (Target), + Selector_Name => + New_Occurrence_Of (Selector, Loc)), + Typ => Etype (Selector), + Enclos_Type => Typ, With_Default_Init => True)); -- Prepare for component assignment diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index e69bb765f04..5e5877e20b5 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -211,10 +211,10 @@ package body Freeze is begin - -- if the renamed subprogram is intrinsic, there is no need for a - -- wrapper body: we set the alias that will be called and expanded - -- which completes the declaration. This transformation is only - -- legal if the renamed entity has already been elaborated. + -- If the renamed subprogram is intrinsic, there is no need for a + -- wrapper body: we set the alias that will be called and expanded which + -- completes the declaration. This transformation is only legal if the + -- renamed entity has already been elaborated. -- Note that it is legal for a renaming_as_body to rename an intrinsic -- subprogram, as long as the renaming occurs before the new entity diff --git a/gcc/ada/g-mbdira.adb b/gcc/ada/g-mbdira.adb index 20cb746d339..27344dc454d 100644 --- a/gcc/ada/g-mbdira.adb +++ b/gcc/ada/g-mbdira.adb @@ -2,7 +2,7 @@ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- --- G N A T . M B S S _ D I S C R E T E _ R A N D O M -- +-- G N A T . M B B S _ D I S C R E T E _ R A N D O M -- -- -- -- B o d y -- -- -- diff --git a/gcc/ada/g-mbdira.ads b/gcc/ada/g-mbdira.ads index 5c614e4ec42..c29667e1a0b 100644 --- a/gcc/ada/g-mbdira.ads +++ b/gcc/ada/g-mbdira.ads @@ -2,7 +2,7 @@ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- --- G N A T . M B S S _ D I S C R E T E _ R A N D O M -- +-- G N A T . M B B S _ D I S C R E T E _ R A N D O M -- -- -- -- S p e c -- -- -- diff --git a/gcc/ada/g-mbflra.adb b/gcc/ada/g-mbflra.adb index cf455707f64..2b4037e9a3d 100644 --- a/gcc/ada/g-mbflra.adb +++ b/gcc/ada/g-mbflra.adb @@ -2,7 +2,7 @@ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- --- G N A T . M B S S _ F L O A T _ R A N D O M -- +-- G N A T . M B B S _ F L O A T _ R A N D O M -- -- -- -- B o d y -- -- -- diff --git a/gcc/ada/g-mbflra.ads b/gcc/ada/g-mbflra.ads index f9ad5af4238..4deac482b52 100644 --- a/gcc/ada/g-mbflra.ads +++ b/gcc/ada/g-mbflra.ads @@ -2,7 +2,7 @@ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- --- G N A T . M B S S _ F L O A T _ R A N D O M -- +-- G N A T . M B B S _ F L O A T _ R A N D O M -- -- -- -- S p e c -- -- -- diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index f3089d44f6a..9fe022bbd22 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -363,6 +363,8 @@ The GNAT Library * GNAT.IO (g-io.ads):: * GNAT.IO_Aux (g-io_aux.ads):: * GNAT.Lock_Files (g-locfil.ads):: +* GNAT.MBBS_Discrete_Random (g-mbdira.ads):: +* GNAT.MBBS_Float_Random (g-mbflra.ads):: * GNAT.MD5 (g-md5.ads):: * GNAT.Memory_Dump (g-memdum.ads):: * GNAT.Most_Recent_Exception (g-moreex.ads):: @@ -13547,6 +13549,8 @@ of GNAT, and will generate a warning message. * GNAT.IO (g-io.ads):: * GNAT.IO_Aux (g-io_aux.ads):: * GNAT.Lock_Files (g-locfil.ads):: +* GNAT.MBBS_Discrete_Random (g-mbdira.ads):: +* GNAT.MBBS_Float_Random (g-mbflra.ads):: * GNAT.MD5 (g-md5.ads):: * GNAT.Memory_Dump (g-memdum.ads):: * GNAT.Most_Recent_Exception (g-moreex.ads):: @@ -14431,6 +14435,24 @@ for whether a file exists, and functions for reading a line of text. Provides a general interface for using files as locks. Can be used for providing program level synchronization. +@node GNAT.MBBS_Discrete_Random (g-mbdira.ads) +@section @code{GNAT.MBBS_Discrete_Random} (@file{g-mbdira.ads}) +@cindex @code{GNAT.MBBS_Discrete_Random} (@file{g-mbdira.ads}) +@cindex Random number generation + +@noindent +The original implementation of @code{Ada.Numerics.Discrete_Random}. Uses +a modified version of the Blum-Blum-Shub generator. + +@node GNAT.MBBS_Float_Random (g-mbflra.ads) +@section @code{GNAT.MBBS_Float_Random} (@file{g-mbflra.ads}) +@cindex @code{GNAT.MBBS_Float_Random} (@file{g-mbflra.ads}) +@cindex Random number generation + +@noindent +The original implementation of @code{Ada.Numerics.Float_Random}. Uses +a modified version of the Blum-Blum-Shub generator. + @node GNAT.MD5 (g-md5.ads) @section @code{GNAT.MD5} (@file{g-md5.ads}) @cindex @code{GNAT.MD5} (@file{g-md5.ads}) diff --git a/gcc/ada/s-rannum.adb b/gcc/ada/s-rannum.adb index c161b6ebbe0..29a8e949c82 100644 --- a/gcc/ada/s-rannum.adb +++ b/gcc/ada/s-rannum.adb @@ -203,33 +203,32 @@ package body System.Random_Numbers is function Random_Float_Template (Gen : Generator) return Real is -- This code generates random floating-point numbers from unsigned - -- integers. Assuming that Real'Machine_Radix = 2, it can deliver - -- all machine values of type Real (at least as implied by - -- Real'Machine_Mantissa and Real'Machine_Emin), which is not true - -- of the standard method (to which we fall back for non-binary - -- radix): computing Real() / (+1). - -- To do so, we first extract an (M-1)-bit significand (where M - -- is Real'Machine_Mantissa), and then decide on a normalized - -- exponent by repeated coin flips, decrementing from 0 as long as - -- we flip heads (1 bits). This yields the proper geometric - -- distribution for the exponent: in a uniformly distributed set of - -- floating-point numbers, 1/2 of them will be in [0.5, 1), 1/4 will - -- be in [0.25, 0.5), and so forth. If the process reaches - -- Machine_Emin (an extremely rare event), it uses the selected - -- mantissa bits as an unnormalized fraction with Machine_Emin as - -- exponent. Otherwise, it adds a leading bit to the selected - -- mantissa bits (thus giving a normalized fraction) and adjusts by - -- the chosen exponent. The algorithm attempts to be stingy with - -- random integers. In the worst case, it can consume roughly - -- -Real'Machine_Emin/32 32-bit integers, but this case occurs with - -- probability 2**Machine_Emin, and the expected number of calls to - -- integer-valued Random is 1. + -- integers. Assuming that Real'Machine_Radix = 2, it can deliver all + -- machine values of type Real (as implied by Real'Machine_Mantissa and + -- Real'Machine_Emin), which is not true of the standard method (to + -- which we fall back for non-binary radix): computing Real() / (+1). To do so, we first extract an + -- (M-1)-bit significand (where M is Real'Machine_Mantissa), and then + -- decide on a normalized exponent by repeated coin flips, decrementing + -- from 0 as long as we flip heads (1 bits). This yields the proper + -- geometric distribution for the exponent: in a uniformly distributed + -- set of floating-point numbers, 1/2 of them will be in [0.5, 1), 1/4 + -- will be in [0.25, 0.5), and so forth. If the process reaches + -- Machine_Emin (an extremely rare event), it uses the selected mantissa + -- bits as an unnormalized fraction with Machine_Emin as exponent. + -- Otherwise, it adds a leading bit to the selected mantissa bits (thus + -- giving a normalized fraction) and adjusts by the chosen exponent. The + -- algorithm attempts to be stingy with random integers. In the worst + -- case, it can consume roughly -Real'Machine_Emin/32 32-bit integers, + -- but this case occurs with probability 2**Machine_Emin, and the + -- expected number of calls to integer-valued Random is 1. begin if Real'Machine_Radix /= 2 then declare - Val : constant Real := Real'Machine - (Real (Unsigned'(Random (Gen))) * 2.0**(-Unsigned'Size)); + Val : constant Real := + Real'Machine + (Real (Unsigned'(Random (Gen))) * 2.0**(-Unsigned'Size)); begin if Val < 1.0 then return Real'Base (Val); @@ -237,20 +236,21 @@ package body System.Random_Numbers is return Real'Pred (1.0); end if; end; + else declare Mant_Bits : constant Integer := Real'Machine_Mantissa - 1; Mant_Mask : constant Unsigned := 2**Mant_Bits - 1; Adjust32 : constant Integer := Real'Size - Unsigned_32'Size; Leftover : constant Integer := - Unsigned'Size - Real'Machine_Mantissa + 1; - + Unsigned'Size - Real'Machine_Mantissa + 1; V : constant Unsigned := Random (Gen); Mant : constant Unsigned := V and Mant_Mask; Rand_Bits : Unsigned_32; Exp : Integer; Bits_Left : Integer; Result : Real; + begin Rand_Bits := Unsigned_32 (Shift_Right (V, Adjust32)); Exp := 0; @@ -271,6 +271,7 @@ package body System.Random_Numbers is Rand_Bits := Random (Gen); end if; end loop; + return Result; end; end if; diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index 5ce3ea6e83a..5ff55cec1b2 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -1800,8 +1800,8 @@ package body Sem_Aggr is elsif Is_Tagged_Type (Etype (Expression (Assoc))) then Check_Dynamically_Tagged_Expression - (Expr => Expression (Assoc), - Typ => Component_Type (Etype (N)), + (Expr => Expression (Assoc), + Typ => Component_Type (Etype (N)), Related_Nod => N); end if; diff --git a/gcc/ada/types.ads b/gcc/ada/types.ads index bb3c62d23e3..5d7784dc03b 100644 --- a/gcc/ada/types.ads +++ b/gcc/ada/types.ads @@ -503,10 +503,10 @@ package Types is -- The type Char is used for character data internally in the compiler, but -- character codes in the source are represented by the Char_Code type. -- Each character literal in the source is interpreted as being one of the - -- 16#7FFF_FFFF possible Wide_Wide_Character codes, and a unique Integer - -- Value is assigned, corresponding to the UTF_32 value, which also - -- corresponds to the POS value in the Wide_Wide_Character type, and also - -- corresponds to the POS value in the Wide_Character and Character types + -- 16#7FFF_FFFF# possible Wide_Wide_Character codes, and a unique Integer + -- value is assigned, corresponding to the UTF-32 value, which also + -- corresponds to the Pos value in the Wide_Wide_Character type, and also + -- corresponds to the Pos value in the Wide_Character and Character types -- for values that are in appropriate range. String literals are similarly -- interpreted as a sequence of such codes. -- 2.30.2