[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Fri, 24 Jan 2014 16:22:02 +0000 (17:22 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Fri, 24 Jan 2014 16:22:02 +0000 (17:22 +0100)
2014-01-24  Eric Botcazou  <ebotcazou@adacore.com>

* set_targ.adb: Set Short_Enums.
* gcc-interface/lang.opt (fshort-enums): New option.
* gcc-interface/misc.c (gnat_handle_option): Handle it.
(gnat_post_options): Do not modify the global settings.

2014-01-24  Robert Dewar  <dewar@adacore.com>

* g-rannum.ads, g-rannum.adb (Random_Ordinary_Fixed): New generic
function.
(Random_Decimal_Fixed): New generic function.
* s-rannum.ads: Minor comment clarifications.

From-SVN: r207049

gcc/ada/ChangeLog
gcc/ada/g-rannum.adb
gcc/ada/g-rannum.ads
gcc/ada/gcc-interface/lang.opt
gcc/ada/gcc-interface/misc.c
gcc/ada/s-rannum.ads
gcc/ada/set_targ.adb

index 686e96e7b8e879c20899db500fbc2cb82346d9fb..f0cb5ee91cac8eee356521ff2390ba9fd06c9965 100644 (file)
@@ -1,3 +1,17 @@
+2014-01-24  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * set_targ.adb: Set Short_Enums.
+       * gcc-interface/lang.opt (fshort-enums): New option.
+       * gcc-interface/misc.c (gnat_handle_option): Handle it.
+       (gnat_post_options): Do not modify the global settings.
+
+2014-01-24  Robert Dewar  <dewar@adacore.com>
+
+       * g-rannum.ads, g-rannum.adb (Random_Ordinary_Fixed): New generic
+       function.
+       (Random_Decimal_Fixed): New generic function.
+       * s-rannum.ads: Minor comment clarifications.
+
 2014-01-24  Robert Dewar  <dewar@adacore.com>
 
        * back_end.adb: Remove Short_Enums handling (handled in
index e35c86cb2813ac30addbaaf2c50f61e5465be97b..a868f08123e566a74792bb469269e4635d919214 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---      Copyright (C) 2007-2009  Free Software Foundation, Inc.             --
+--          Copyright (C) 2007-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -30,8 +30,9 @@
 ------------------------------------------------------------------------------
 
 with Ada.Numerics.Long_Elementary_Functions;
-use Ada.Numerics.Long_Elementary_Functions;
+use  Ada.Numerics.Long_Elementary_Functions;
 with Ada.Unchecked_Conversion;
+
 with System.Random_Numbers; use System.Random_Numbers;
 
 package body GNAT.Random_Numbers is
@@ -87,6 +88,40 @@ package body GNAT.Random_Numbers is
       return F (Gen.Rep, Min, Max);
    end Random_Discrete;
 
+   --------------------------
+   -- Random_Decimal_Fixed --
+   --------------------------
+
+   function Random_Decimal_Fixed
+     (Gen : Generator;
+      Min : Result_Subtype := Default_Min;
+      Max : Result_Subtype := Result_Subtype'Last) return Result_Subtype
+   is
+      subtype IntV is Integer_64 range
+        Integer_64'Integer_Value (Min) ..
+        Integer_64'Integer_Value (Max);
+      function R is new Random_Discrete (Integer_64, IntV'First);
+   begin
+      return Result_Subtype'Fixed_Value (R (Gen, IntV'First, IntV'Last));
+   end Random_Decimal_Fixed;
+
+   ---------------------------
+   -- Random_Ordinary_Fixed --
+   ---------------------------
+
+   function Random_Ordinary_Fixed
+     (Gen : Generator;
+      Min : Result_Subtype := Default_Min;
+      Max : Result_Subtype := Result_Subtype'Last) return Result_Subtype
+   is
+      subtype IntV is Integer_64 range
+        Integer_64'Integer_Value (Min) ..
+        Integer_64'Integer_Value (Max);
+      function R is new Random_Discrete (Integer_64, IntV'First);
+   begin
+      return Result_Subtype'Fixed_Value (R (Gen, IntV'First, IntV'Last));
+   end Random_Ordinary_Fixed;
+
    ------------
    -- Random --
    ------------
@@ -137,7 +172,7 @@ package body GNAT.Random_Numbers is
    -- Random_Float --
    ------------------
 
-   function Random_Float (Gen   : Generator) return Result_Subtype is
+   function Random_Float (Gen : Generator) return Result_Subtype is
       function F is new System.Random_Numbers.Random_Float (Result_Subtype);
    begin
       return F (Gen.Rep);
index 353e21cd0f1f93ae39b50e38d7133270f6e0696f..010c21c6cde626e0bd8d5cc56b65f39f51eeece1 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---      Copyright (C) 2007-2009  Free Software Foundation, Inc.             --
+--          Copyright (C) 2007-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -78,10 +78,28 @@ package GNAT.Random_Numbers is
       Max   : Result_Subtype := Result_Subtype'Last) return Result_Subtype;
    --  Returns pseudo-random numbers uniformly distributed on Min .. Max
 
+   generic
+      type Result_Subtype is delta <>;
+      Default_Min : Result_Subtype := 0.0;
+   function Random_Ordinary_Fixed
+     (Gen   : Generator;
+      Min   : Result_Subtype := Default_Min;
+      Max   : Result_Subtype := Result_Subtype'Last) return Result_Subtype;
+   --  Returns pseudo-random numbers uniformly distributed on Min .. Max
+
+   generic
+      type Result_Subtype is delta <> digits <>;
+      Default_Min : Result_Subtype := 0.0;
+   function Random_Decimal_Fixed
+     (Gen   : Generator;
+      Min   : Result_Subtype := Default_Min;
+      Max   : Result_Subtype := Result_Subtype'Last) return Result_Subtype;
+   --  Returns pseudo-random numbers uniformly distributed on Min .. Max
+
    generic
       type Result_Subtype is digits <>;
    function Random_Float (Gen   : Generator) return Result_Subtype;
-   --  Returns pseudo-random numbers uniformly distributed on [0 .. 1)
+   --  Returns pseudo-random numbers uniformly distributed on [0.0 .. 1.0)
 
    function Random_Gaussian (Gen : Generator) return Long_Float;
    function Random_Gaussian (Gen : Generator) return Float;
index debeff660e0a5ab355e1c2e8701a2544c3b1d89c..004388ba26a870699814ffdda93046836ef46a71 100644 (file)
@@ -1,6 +1,5 @@
 ; Options for the Ada front end.
-; Copyright (C) 2003, 2007, 2008, 2010, 2011, 2012
-; Free Software Foundation, Inc.
+; Copyright (C) 2003-2013 Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
 ;
@@ -18,7 +17,6 @@
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
 
-
 ; See the GCC internals manual for a description of this file's format.
 
 ; Please try to keep this file in ASCII collating order.
@@ -74,6 +72,10 @@ fRTS=
 Ada AdaWhy AdaSCIL Joined RejectNegative
 Select the runtime
 
+fshort-enums
+Ada AdaWhy AdaSCIL
+Use the narrowest integer type possible for enumeration types
+
 gant
 Ada AdaWhy AdaSCIL Joined Undocumented
 Catch typos
index 0272050954f053ddc0ad73d3531c5035c3e30640..5f135a063b2001f758125e023bbe8a925fcb92bb 100644 (file)
@@ -151,6 +151,10 @@ gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value,
       /* These are handled by the front-end.  */
       break;
 
+    case OPT_fshort_enums:
+      /* This is handled by the middle-end.  */
+      break;
+
     default:
       gcc_unreachable ();
     }
@@ -259,13 +263,14 @@ gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
   optimize_size = global_options.x_optimize_size;
   flag_compare_debug = global_options.x_flag_compare_debug;
   flag_stack_check = global_options.x_flag_stack_check;
-
-  /* Unfortunately the post_options hook is called before setting the
-     short_enums flag. Set it now.  */
-  if (global_options.x_flag_short_enums == 2)
-    global_options.x_flag_short_enums = targetm.default_short_enums ();
   flag_short_enums = global_options.x_flag_short_enums;
 
+  /* Unfortunately the post_options hook is called before the value of
+     flag_short_enums is autodetected, if need be.  Mimic the process
+     for our private flag_short_enums.  */
+  if (flag_short_enums == 2)
+    flag_short_enums = targetm.default_short_enums ();
+
   return false;
 }
 
index 0d2a7e9dee72251f49346b6c00d441ef5eadb5ab..a412b9c85c9aec9477d24015f0af2401382eae17 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2007-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 2007-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -56,12 +56,16 @@ with Interfaces;
 package System.Random_Numbers is
 
    type Generator is limited private;
+   --  Generator encodes the current state of a random number stream, it is
+   --  provided as input to produce the next random number, and updated so
+   --  that it is ready to produce the next one.
+
    type State is private;
    --  A non-limited version of a Generator's internal state
 
    function Random (Gen : Generator) return Float;
    function Random (Gen : Generator) return Long_Float;
-   --  Return pseudo-random numbers uniformly distributed on [0 .. 1)
+   --  Return pseudo-random numbers uniformly distributed on [0.0 .. 1.0)
 
    function Random (Gen : Generator) return Interfaces.Unsigned_32;
    function Random (Gen : Generator) return Interfaces.Unsigned_64;
index 0dc9b839b25caa09b6afdf03e0ed4543a765bab1..83ba3313483ba292e441c364a7d922559c142af4 100755 (executable)
@@ -573,6 +573,7 @@ begin
       Maximum_Alignment          := Get_Maximum_Alignment;
       Max_Unaligned_Field        := Get_Max_Unaligned_Field;
       Pointer_Size               := Get_Pointer_Size;
+      Short_Enums                := Get_Short_Enums;
       Short_Size                 := Get_Short_Size;
       Strict_Alignment           := Get_Strict_Alignment;
       System_Allocator_Alignment := Get_System_Allocator_Alignment;