OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-wtmoau.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --         A D A . W I D E _ 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.Wide_Text_IO.Generic_Aux; use Ada.Wide_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.Wide_Text_IO.Modular_Aux is
47
48    use System.Unsigned_Types;
49
50    -----------------------
51    -- Local Subprograms --
52    -----------------------
53
54    procedure Load_Modular
55      (File : in 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  : in File_Type;
68       Item  : out Long_Long_Unsigned;
69       Width : in 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  : in File_Type;
93       Item  : out Unsigned;
94       Width : in 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 : in 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
133    end Gets_LLU;
134
135    --------------
136    -- Gets_Uns --
137    --------------
138
139    procedure Gets_Uns
140      (From : in String;
141       Item : out Unsigned;
142       Last : out Positive)
143    is
144       Pos : aliased Integer;
145
146    begin
147       String_Skip (From, Pos);
148       Item := Scan_Unsigned (From, Pos'Access, From'Last);
149       Last := Pos - 1;
150
151    exception
152       when Constraint_Error =>
153          Last := Pos - 1;
154          raise Data_Error;
155
156    end Gets_Uns;
157
158    ------------------
159    -- Load_Modular --
160    ------------------
161
162    procedure Load_Modular
163      (File : in File_Type;
164       Buf  : out String;
165       Ptr  : in out Natural)
166    is
167       Hash_Loc : Natural;
168       Loaded   : Boolean;
169
170    begin
171       Load_Skip (File);
172
173       --  Note: it is a bit strange to allow a minus sign here, but it seems
174       --  consistent with the general behavior expected by the ACVC tests
175       --  which is to scan past junk and then signal data error, see ACVC
176       --  test CE3704F, case (6), which is for signed integer exponents,
177       --  which seems a similar case.
178
179       Load (File, Buf, Ptr, '+', '-');
180       Load_Digits (File, Buf, Ptr, Loaded);
181
182       if Loaded then
183          Load (File, Buf, Ptr, '#', ':', Loaded);
184
185          if Loaded then
186             Hash_Loc := Ptr;
187             Load_Extended_Digits (File, Buf, Ptr);
188             Load (File, Buf, Ptr, Buf (Hash_Loc));
189          end if;
190
191          Load (File, Buf, Ptr, 'E', 'e', Loaded);
192
193          if Loaded then
194
195             --  Note: it is strange to allow a minus sign, since the syntax
196             --  does not, but that is what ACVC test CE3704F, case (6) wants
197             --  for the signed case, and there seems no good reason to treat
198             --  exponents differently for the signed and unsigned cases.
199
200             Load (File, Buf, Ptr, '+', '-');
201             Load_Digits (File, Buf, Ptr);
202          end if;
203       end if;
204    end Load_Modular;
205
206    -------------
207    -- Put_LLU --
208    -------------
209
210    procedure Put_LLU
211      (File  : in File_Type;
212       Item  : in Long_Long_Unsigned;
213       Width : in Field;
214       Base  : in Number_Base)
215    is
216       Buf : String (1 .. Field'Last);
217       Ptr : Natural := 0;
218
219    begin
220       if Base = 10 and then Width = 0 then
221          Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
222       elsif Base = 10 then
223          Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
224       else
225          Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
226       end if;
227
228       Put_Item (File, Buf (1 .. Ptr));
229    end Put_LLU;
230
231    -------------
232    -- Put_Uns --
233    -------------
234
235    procedure Put_Uns
236      (File  : in File_Type;
237       Item  : in Unsigned;
238       Width : in Field;
239       Base  : in Number_Base)
240    is
241       Buf : String (1 .. Field'Last);
242       Ptr : Natural := 0;
243
244    begin
245       if Base = 10 and then Width = 0 then
246          Set_Image_Unsigned (Item, Buf, Ptr);
247       elsif Base = 10 then
248          Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
249       else
250          Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
251       end if;
252
253       Put_Item (File, Buf (1 .. Ptr));
254    end Put_Uns;
255
256    --------------
257    -- Puts_LLU --
258    --------------
259
260    procedure Puts_LLU
261      (To   : out String;
262       Item : in Long_Long_Unsigned;
263       Base : in Number_Base)
264    is
265       Buf : String (1 .. Field'Last);
266       Ptr : Natural := 0;
267
268    begin
269       if Base = 10 then
270          Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
271       else
272          Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
273       end if;
274
275       if Ptr > To'Length then
276          raise Layout_Error;
277       else
278          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
279       end if;
280    end Puts_LLU;
281
282    --------------
283    -- Puts_Uns --
284    --------------
285
286    procedure Puts_Uns
287      (To   : out String;
288       Item : in Unsigned;
289       Base : in Number_Base)
290    is
291       Buf : String (1 .. Field'Last);
292       Ptr : Natural := 0;
293
294    begin
295       if Base = 10 then
296          Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
297       else
298          Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
299       end if;
300
301       if Ptr > To'Length then
302          raise Layout_Error;
303       else
304          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
305       end if;
306    end Puts_Uns;
307
308 end Ada.Wide_Text_IO.Modular_Aux;