OSDN Git Service

* Makefile.in (reload1.o-warn): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-wtinau.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --         A D A . W I D E _ T E X T _ I O . I N T E G E R  _ A U X         --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 with Ada.Wide_Text_IO.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
35
36 with System.Img_BIU; use System.Img_BIU;
37 with System.Img_Int; use System.Img_Int;
38 with System.Img_LLB; use System.Img_LLB;
39 with System.Img_LLI; use System.Img_LLI;
40 with System.Img_LLW; use System.Img_LLW;
41 with System.Img_WIU; use System.Img_WIU;
42 with System.Val_Int; use System.Val_Int;
43 with System.Val_LLI; use System.Val_LLI;
44
45 package body Ada.Wide_Text_IO.Integer_Aux is
46
47    -----------------------
48    -- Local Subprograms --
49    -----------------------
50
51    procedure Load_Integer
52      (File : File_Type;
53       Buf  : out String;
54       Ptr  : in out Natural);
55    --  This is an auxiliary routine that is used to load an possibly signed
56    --  integer literal value from the input file into Buf, starting at Ptr + 1.
57    --  On return, Ptr is set to the last character stored.
58
59    -------------
60    -- Get_Int --
61    -------------
62
63    procedure Get_Int
64      (File  : File_Type;
65       Item  : out Integer;
66       Width : Field)
67    is
68       Buf  : String (1 .. Field'Last);
69       Ptr  : aliased Integer := 1;
70       Stop : Integer := 0;
71
72    begin
73       if Width /= 0 then
74          Load_Width (File, Width, Buf, Stop);
75          String_Skip (Buf, Ptr);
76       else
77          Load_Integer (File, Buf, Stop);
78       end if;
79
80       Item := Scan_Integer (Buf, Ptr'Access, Stop);
81       Check_End_Of_Field (Buf, Stop, Ptr, Width);
82    end Get_Int;
83
84    -------------
85    -- Get_LLI --
86    -------------
87
88    procedure Get_LLI
89      (File  : File_Type;
90       Item  : out Long_Long_Integer;
91       Width : Field)
92    is
93       Buf  : String (1 .. Field'Last);
94       Ptr  : aliased Integer := 1;
95       Stop : Integer := 0;
96
97    begin
98       if Width /= 0 then
99          Load_Width (File, Width, Buf, Stop);
100          String_Skip (Buf, Ptr);
101       else
102          Load_Integer (File, Buf, Stop);
103       end if;
104
105       Item := Scan_Long_Long_Integer (Buf, Ptr'Access, Stop);
106       Check_End_Of_Field (Buf, Stop, Ptr, Width);
107    end Get_LLI;
108
109    --------------
110    -- Gets_Int --
111    --------------
112
113    procedure Gets_Int
114      (From : String;
115       Item : out Integer;
116       Last : out Positive)
117    is
118       Pos : aliased Integer;
119
120    begin
121       String_Skip (From, Pos);
122       Item := Scan_Integer (From, Pos'Access, From'Last);
123       Last := Pos - 1;
124
125    exception
126       when Constraint_Error =>
127          raise Data_Error;
128    end Gets_Int;
129
130    --------------
131    -- Gets_LLI --
132    --------------
133
134    procedure Gets_LLI
135      (From : String;
136       Item : out Long_Long_Integer;
137       Last : out Positive)
138    is
139       Pos : aliased Integer;
140
141    begin
142       String_Skip (From, Pos);
143       Item := Scan_Long_Long_Integer (From, Pos'Access, From'Last);
144       Last := Pos - 1;
145
146    exception
147       when Constraint_Error =>
148          raise Data_Error;
149    end Gets_LLI;
150
151    ------------------
152    -- Load_Integer --
153    ------------------
154
155    procedure Load_Integer
156      (File : File_Type;
157       Buf  : out String;
158       Ptr  : in out Natural)
159    is
160       Hash_Loc : Natural;
161       Loaded   : Boolean;
162
163    begin
164       Load_Skip (File);
165       Load (File, Buf, Ptr, '+', '-');
166
167       Load_Digits (File, Buf, Ptr, Loaded);
168
169       if Loaded then
170          Load (File, Buf, Ptr, '#', ':', Loaded);
171
172          if Loaded then
173             Hash_Loc := Ptr;
174             Load_Extended_Digits (File, Buf, Ptr);
175             Load (File, Buf, Ptr, Buf (Hash_Loc));
176          end if;
177
178          Load (File, Buf, Ptr, 'E', 'e', Loaded);
179
180          if Loaded then
181
182             --  Note: it is strange to allow a minus sign, since the syntax
183             --  does not, but that is what ACVC test CE3704F, case (6) wants.
184
185             Load (File, Buf, Ptr, '+', '-');
186             Load_Digits (File, Buf, Ptr);
187          end if;
188       end if;
189    end Load_Integer;
190
191    -------------
192    -- Put_Int --
193    -------------
194
195    procedure Put_Int
196      (File  : File_Type;
197       Item  : Integer;
198       Width : Field;
199       Base  : Number_Base)
200    is
201       Buf : String (1 .. Field'Last);
202       Ptr : Natural := 0;
203
204    begin
205       if Base = 10 and then Width = 0 then
206          Set_Image_Integer (Item, Buf, Ptr);
207       elsif Base = 10 then
208          Set_Image_Width_Integer (Item, Width, Buf, Ptr);
209       else
210          Set_Image_Based_Integer (Item, Base, Width, Buf, Ptr);
211       end if;
212
213       Put_Item (File, Buf (1 .. Ptr));
214    end Put_Int;
215
216    -------------
217    -- Put_LLI --
218    -------------
219
220    procedure Put_LLI
221      (File  : File_Type;
222       Item  : Long_Long_Integer;
223       Width : Field;
224       Base  : Number_Base)
225    is
226       Buf : String (1 .. Field'Last);
227       Ptr : Natural := 0;
228
229    begin
230       if Base = 10 and then Width = 0 then
231          Set_Image_Long_Long_Integer (Item, Buf, Ptr);
232       elsif Base = 10 then
233          Set_Image_Width_Long_Long_Integer (Item, Width, Buf, Ptr);
234       else
235          Set_Image_Based_Long_Long_Integer (Item, Base, Width, Buf, Ptr);
236       end if;
237
238       Put_Item (File, Buf (1 .. Ptr));
239    end Put_LLI;
240
241    --------------
242    -- Puts_Int --
243    --------------
244
245    procedure Puts_Int
246      (To   : out String;
247       Item : Integer;
248       Base : Number_Base)
249    is
250       Buf : String (1 .. Field'Last);
251       Ptr : Natural := 0;
252
253    begin
254       if Base = 10 then
255          Set_Image_Width_Integer (Item, To'Length, Buf, Ptr);
256       else
257          Set_Image_Based_Integer (Item, Base, To'Length, Buf, Ptr);
258       end if;
259
260       if Ptr > To'Length then
261          raise Layout_Error;
262       else
263          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
264       end if;
265    end Puts_Int;
266
267    --------------
268    -- Puts_LLI --
269    --------------
270
271    procedure Puts_LLI
272      (To   : out String;
273       Item : Long_Long_Integer;
274       Base : Number_Base)
275    is
276       Buf : String (1 .. Field'Last);
277       Ptr : Natural := 0;
278
279    begin
280       if Base = 10 then
281          Set_Image_Width_Long_Long_Integer (Item, To'Length, Buf, Ptr);
282       else
283          Set_Image_Based_Long_Long_Integer (Item, Base, To'Length, Buf, Ptr);
284       end if;
285
286       if Ptr > To'Length then
287          raise Layout_Error;
288       else
289          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
290       end if;
291    end Puts_LLI;
292
293 end Ada.Wide_Text_IO.Integer_Aux;