OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-timoau.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --              A D A . T E X T _ I O . M O D U L A R  _ A U X              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNAT was originally developed  by the GNAT team at  New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
36
37 with System.Img_BIU; use System.Img_BIU;
38 with System.Img_Uns; use System.Img_Uns;
39 with System.Img_LLB; use System.Img_LLB;
40 with System.Img_LLU; use System.Img_LLU;
41 with System.Img_LLW; use System.Img_LLW;
42 with System.Img_WIU; use System.Img_WIU;
43 with System.Val_Uns; use System.Val_Uns;
44 with System.Val_LLU; use System.Val_LLU;
45
46 package body Ada.Text_IO.Modular_Aux is
47
48    use System.Unsigned_Types;
49
50    -----------------------
51    -- Local Subprograms --
52    -----------------------
53
54    procedure Load_Modular
55      (File : File_Type;
56       Buf  : out String;
57       Ptr  : in out Natural);
58    --  This is an auxiliary routine that is used to load an possibly signed
59    --  modular literal value from the input file into Buf, starting at Ptr + 1.
60    --  Ptr is left set to the last character stored.
61
62    -------------
63    -- Get_LLU --
64    -------------
65
66    procedure Get_LLU
67      (File  : File_Type;
68       Item  : out Long_Long_Unsigned;
69       Width : Field)
70    is
71       Buf  : String (1 .. Field'Last);
72       Stop : Integer := 0;
73       Ptr  : aliased Integer := 1;
74
75    begin
76       if Width /= 0 then
77          Load_Width (File, Width, Buf, Stop);
78          String_Skip (Buf, Ptr);
79       else
80          Load_Modular (File, Buf, Stop);
81       end if;
82
83       Item := Scan_Long_Long_Unsigned (Buf, Ptr'Access, Stop);
84       Check_End_Of_Field (Buf, Stop, Ptr, Width);
85    end Get_LLU;
86
87    -------------
88    -- Get_Uns --
89    -------------
90
91    procedure Get_Uns
92      (File  : File_Type;
93       Item  : out Unsigned;
94       Width : Field)
95    is
96       Buf  : String (1 .. Field'Last);
97       Stop : Integer := 0;
98       Ptr  : aliased Integer := 1;
99
100    begin
101       if Width /= 0 then
102          Load_Width (File, Width, Buf, Stop);
103          String_Skip (Buf, Ptr);
104       else
105          Load_Modular (File, Buf, Stop);
106       end if;
107
108       Item := Scan_Unsigned (Buf, Ptr'Access, Stop);
109       Check_End_Of_Field (Buf, Stop, Ptr, Width);
110    end Get_Uns;
111
112    --------------
113    -- Gets_LLU --
114    --------------
115
116    procedure Gets_LLU
117      (From : String;
118       Item : out Long_Long_Unsigned;
119       Last : out Positive)
120    is
121       Pos : aliased Integer;
122
123    begin
124       String_Skip (From, Pos);
125       Item := Scan_Long_Long_Unsigned (From, Pos'Access, From'Last);
126       Last := Pos - 1;
127
128    exception
129       when Constraint_Error =>
130          Last := Pos - 1;
131          raise Data_Error;
132    end Gets_LLU;
133
134    --------------
135    -- Gets_Uns --
136    --------------
137
138    procedure Gets_Uns
139      (From : String;
140       Item : out Unsigned;
141       Last : out Positive)
142    is
143       Pos : aliased Integer;
144
145    begin
146       String_Skip (From, Pos);
147       Item := Scan_Unsigned (From, Pos'Access, From'Last);
148       Last := Pos - 1;
149
150    exception
151       when Constraint_Error =>
152          Last := Pos - 1;
153          raise Data_Error;
154    end Gets_Uns;
155
156    ------------------
157    -- Load_Modular --
158    ------------------
159
160    procedure Load_Modular
161      (File : File_Type;
162       Buf  : out String;
163       Ptr  : in out Natural)
164    is
165       Hash_Loc : Natural;
166       Loaded   : Boolean;
167
168    begin
169       Load_Skip (File);
170
171       --  Note: it is a bit strange to allow a minus sign here, but it seems
172       --  consistent with the general behavior expected by the ACVC tests
173       --  which is to scan past junk and then signal data error, see ACVC
174       --  test CE3704F, case (6), which is for signed integer exponents,
175       --  which seems a similar case.
176
177       Load (File, Buf, Ptr, '+', '-');
178       Load_Digits (File, Buf, Ptr, Loaded);
179
180       if Loaded then
181          Load (File, Buf, Ptr, '#', ':', Loaded);
182
183          if Loaded then
184             Hash_Loc := Ptr;
185             Load_Extended_Digits (File, Buf, Ptr);
186             Load (File, Buf, Ptr, Buf (Hash_Loc));
187          end if;
188
189          Load (File, Buf, Ptr, 'E', 'e', Loaded);
190
191          if Loaded then
192
193             --  Note: it is strange to allow a minus sign, since the syntax
194             --  does not, but that is what ACVC test CE3704F, case (6) wants
195             --  for the signed case, and there seems no good reason to treat
196             --  exponents differently for the signed and unsigned cases.
197
198             Load (File, Buf, Ptr, '+', '-');
199             Load_Digits (File, Buf, Ptr);
200          end if;
201       end if;
202    end Load_Modular;
203
204    -------------
205    -- Put_LLU --
206    -------------
207
208    procedure Put_LLU
209      (File  : File_Type;
210       Item  : Long_Long_Unsigned;
211       Width : Field;
212       Base  : Number_Base)
213    is
214       Buf : String (1 .. Field'Last);
215       Ptr : Natural := 0;
216
217    begin
218       if Base = 10 and then Width = 0 then
219          Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
220       elsif Base = 10 then
221          Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
222       else
223          Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
224       end if;
225
226       Put_Item (File, Buf (1 .. Ptr));
227    end Put_LLU;
228
229    -------------
230    -- Put_Uns --
231    -------------
232
233    procedure Put_Uns
234      (File  : File_Type;
235       Item  : Unsigned;
236       Width : Field;
237       Base  : Number_Base)
238    is
239       Buf : String (1 .. Field'Last);
240       Ptr : Natural := 0;
241
242    begin
243       if Base = 10 and then Width = 0 then
244          Set_Image_Unsigned (Item, Buf, Ptr);
245       elsif Base = 10 then
246          Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
247       else
248          Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
249       end if;
250
251       Put_Item (File, Buf (1 .. Ptr));
252    end Put_Uns;
253
254    --------------
255    -- Puts_LLU --
256    --------------
257
258    procedure Puts_LLU
259      (To   : out String;
260       Item : Long_Long_Unsigned;
261       Base : Number_Base)
262    is
263       Buf : String (1 .. Field'Last);
264       Ptr : Natural := 0;
265
266    begin
267       if Base = 10 then
268          Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
269       else
270          Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
271       end if;
272
273       if Ptr > To'Length then
274          raise Layout_Error;
275       else
276          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
277       end if;
278    end Puts_LLU;
279
280    --------------
281    -- Puts_Uns --
282    --------------
283
284    procedure Puts_Uns
285      (To   : out String;
286       Item : Unsigned;
287       Base : Number_Base)
288    is
289       Buf : String (1 .. Field'Last);
290       Ptr : Natural := 0;
291
292    begin
293       if Base = 10 then
294          Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
295       else
296          Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
297       end if;
298
299       if Ptr > To'Length then
300          raise Layout_Error;
301       else
302          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
303       end if;
304    end Puts_Uns;
305
306 end Ada.Text_IO.Modular_Aux;