OSDN Git Service

* gcc-interface/misc.c (gnat_expand_expr): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-teioed.adb
index b4280c3..8d3e01f 100644 (file)
@@ -6,25 +6,23 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2005, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2009, 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- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
@@ -42,7 +40,7 @@ package body Ada.Text_IO.Editing is
    -- Blank_When_Zero --
    ---------------------
 
-   function Blank_When_Zero (Pic : in Picture) return Boolean is
+   function Blank_When_Zero (Pic : Picture) return Boolean is
    begin
       return Pic.Contents.Original_BWZ;
    end Blank_When_Zero;
@@ -51,7 +49,7 @@ package body Ada.Text_IO.Editing is
    -- Expand --
    ------------
 
-   function Expand (Picture : in String) return String is
+   function Expand (Picture : String) return String is
       Result        : String (1 .. MAX_PICSIZE);
       Picture_Index : Integer := Picture'First;
       Result_Index  : Integer := Result'First;
@@ -84,6 +82,10 @@ package body Ada.Text_IO.Editing is
                --  character has already been made, so a count of one is a
                --  no-op, and a count of zero erases a character.
 
+               if Result_Index + Count - 2 > Result'Last then
+                  raise Picture_Error;
+               end if;
+
                for J in 2 .. Count loop
                   Result (Result_Index + J - 2) := Picture (Picture_Index - 1);
                end loop;
@@ -98,6 +100,10 @@ package body Ada.Text_IO.Editing is
                raise Picture_Error;
 
             when others =>
+               if Result_Index > Result'Last then
+                  raise Picture_Error;
+               end if;
+
                Result (Result_Index) := Picture (Picture_Index);
                Picture_Index := Picture_Index + 1;
                Result_Index := Result_Index + 1;
@@ -124,8 +130,7 @@ package body Ada.Text_IO.Editing is
       Currency_Symbol     : String;
       Fill_Character      : Character;
       Separator_Character : Character;
-      Radix_Point         : Character)
-      return                String
+      Radix_Point         : Character) return String
    is
       Attrs    : Number_Attributes := Parse_Number_String (Number);
       Position : Integer;
@@ -418,7 +423,7 @@ package body Ada.Text_IO.Editing is
                Answer (J) := Separator_Character;
 
             elsif Answer (J) = 'b' then
-               Answer (J) := '*';
+               Answer (J) := Fill_Character;
             end if;
          end loop;
 
@@ -427,7 +432,7 @@ package body Ada.Text_IO.Editing is
          end if;
 
          for J in Pic.Start_Float .. Position loop
-            Answer (J) := '*';
+            Answer (J) := Fill_Character;
          end loop;
 
       else
@@ -929,12 +934,14 @@ package body Ada.Text_IO.Editing is
    --  The following ensures that we return B and not b being careful not
    --  to break things which expect lower case b for blank. See CXF3A02.
 
-   function Pic_String (Pic : in Picture) return String is
+   function Pic_String (Pic : Picture) return String is
       Temp : String (1 .. Pic.Contents.Picture.Length) :=
                               Pic.Contents.Picture.Expanded;
    begin
       for J in Temp'Range loop
-         if Temp (J) = 'b' then Temp (J) := 'B'; end if;
+         if Temp (J) = 'b' then
+            Temp (J) := 'B';
+         end if;
       end loop;
 
       return Temp;
@@ -975,7 +982,7 @@ package body Ada.Text_IO.Editing is
       procedure Debug_Start (Name : String);
       pragma Inline (Debug_Start);
 
-      procedure Debug_Integer  (Value : in Integer; S : String);
+      procedure Debug_Integer  (Value : Integer; S : String);
       pragma Inline (Debug_Integer);
 
       procedure Trailing_Currency;
@@ -1032,7 +1039,7 @@ package body Ada.Text_IO.Editing is
       -- Debug_Integer --
       -------------------
 
-      procedure Debug_Integer  (Value : in Integer; S : String) is
+      procedure Debug_Integer (Value : Integer; S : String) is
          use Ada.Text_IO; --  needed for >
 
       begin
@@ -2449,9 +2456,10 @@ package body Ada.Text_IO.Editing is
 
       procedure Set_State (L : Legality) is
       begin
-         if Debug then Ada.Text_IO.Put_Line
-            ("  Set state from " & Legality'Image (State) &
-                             " to " & Legality'Image (L));
+         if Debug then
+            Ada.Text_IO.Put_Line
+              ("  Set state from " & Legality'Image (State)
+               & " to " & Legality'Image (L));
          end if;
 
          State := L;
@@ -2463,8 +2471,8 @@ package body Ada.Text_IO.Editing is
 
       procedure Skip is
       begin
-         if Debug then Ada.Text_IO.Put_Line
-            ("  Skip " & Pic.Picture.Expanded (Index));
+         if Debug then
+            Ada.Text_IO.Put_Line ("  Skip " & Pic.Picture.Expanded (Index));
          end if;
 
          Index := Index + 1;
@@ -2717,9 +2725,8 @@ package body Ada.Text_IO.Editing is
    ----------------
 
    function To_Picture
-     (Pic_String      : in String;
-      Blank_When_Zero : in Boolean := False)
-      return            Picture
+     (Pic_String      : String;
+      Blank_When_Zero : Boolean := False) return Picture
    is
       Result : Picture;
 
@@ -2745,9 +2752,8 @@ package body Ada.Text_IO.Editing is
    -----------
 
    function Valid
-     (Pic_String      : in String;
-      Blank_When_Zero : in Boolean := False)
-      return            Boolean
+     (Pic_String      : String;
+      Blank_When_Zero : Boolean := False) return Boolean
    is
    begin
       declare
@@ -2764,8 +2770,8 @@ package body Ada.Text_IO.Editing is
 
          --  False only if Blank_When_Zero is True but the pic string has a '*'
 
-         return not Blank_When_Zero or
-           Strings_Fixed.Index (Expanded_Pic, "*") = 0;
+         return not Blank_When_Zero
+           or else Strings_Fixed.Index (Expanded_Pic, "*") = 0;
       end;
 
    exception
@@ -2783,13 +2789,12 @@ package body Ada.Text_IO.Editing is
       -----------
 
       function Image
-        (Item       : in Num;
-         Pic        : in Picture;
-         Currency   : in String    := Default_Currency;
-         Fill       : in Character := Default_Fill;
-         Separator  : in Character := Default_Separator;
-         Radix_Mark : in Character := Default_Radix_Mark)
-         return       String
+        (Item       : Num;
+         Pic        : Picture;
+         Currency   : String    := Default_Currency;
+         Fill       : Character := Default_Fill;
+         Separator  : Character := Default_Separator;
+         Radix_Mark : Character := Default_Radix_Mark) return String
       is
       begin
          return Format_Number
@@ -2802,9 +2807,8 @@ package body Ada.Text_IO.Editing is
       ------------
 
       function Length
-        (Pic      : in Picture;
-         Currency : in String := Default_Currency)
-         return     Natural
+        (Pic      : Picture;
+         Currency : String := Default_Currency) return Natural
       is
          Picstr     : constant String := Pic_String (Pic);
          V_Adjust   : Integer := 0;
@@ -2836,13 +2840,13 @@ package body Ada.Text_IO.Editing is
       ---------
 
       procedure Put
-        (File       : in Text_IO.File_Type;
-         Item       : in Num;
-         Pic        : in Picture;
-         Currency   : in String    := Default_Currency;
-         Fill       : in Character := Default_Fill;
-         Separator  : in Character := Default_Separator;
-         Radix_Mark : in Character := Default_Radix_Mark)
+        (File       : Text_IO.File_Type;
+         Item       : Num;
+         Pic        : Picture;
+         Currency   : String    := Default_Currency;
+         Fill       : Character := Default_Fill;
+         Separator  : Character := Default_Separator;
+         Radix_Mark : Character := Default_Radix_Mark)
       is
       begin
          Text_IO.Put (File, Image (Item, Pic,
@@ -2850,12 +2854,12 @@ package body Ada.Text_IO.Editing is
       end Put;
 
       procedure Put
-        (Item       : in Num;
-         Pic        : in Picture;
-         Currency   : in String    := Default_Currency;
-         Fill       : in Character := Default_Fill;
-         Separator  : in Character := Default_Separator;
-         Radix_Mark : in Character := Default_Radix_Mark)
+        (Item       : Num;
+         Pic        : Picture;
+         Currency   : String    := Default_Currency;
+         Fill       : Character := Default_Fill;
+         Separator  : Character := Default_Separator;
+         Radix_Mark : Character := Default_Radix_Mark)
       is
       begin
          Text_IO.Put (Image (Item, Pic,
@@ -2864,12 +2868,12 @@ package body Ada.Text_IO.Editing is
 
       procedure Put
         (To         : out String;
-         Item       : in Num;
-         Pic        : in Picture;
-         Currency   : in String    := Default_Currency;
-         Fill       : in Character := Default_Fill;
-         Separator  : in Character := Default_Separator;
-         Radix_Mark : in Character := Default_Radix_Mark)
+         Item       : Num;
+         Pic        : Picture;
+         Currency   : String    := Default_Currency;
+         Fill       : Character := Default_Fill;
+         Separator  : Character := Default_Separator;
+         Radix_Mark : Character := Default_Radix_Mark)
       is
          Result : constant String :=
            Image (Item, Pic, Currency, Fill, Separator, Radix_Mark);
@@ -2889,9 +2893,8 @@ package body Ada.Text_IO.Editing is
 
       function Valid
         (Item     : Num;
-         Pic      : in Picture;
-         Currency : in String := Default_Currency)
-         return     Boolean
+         Pic      : Picture;
+         Currency : String := Default_Currency) return Boolean
       is
       begin
          declare