FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / a-timoau.adb
blob4de3bf3185d5f6786b2205f113fdaeb4129d7f87
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 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
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;
46 package body Ada.Text_IO.Modular_Aux is
48 use System.Unsigned_Types;
50 -----------------------
51 -- Local Subprograms --
52 -----------------------
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.
62 -------------
63 -- Get_LLU --
64 -------------
66 procedure Get_LLU
67 (File : File_Type;
68 Item : out Long_Long_Unsigned;
69 Width : Field)
71 Buf : String (1 .. Field'Last);
72 Stop : Integer := 0;
73 Ptr : aliased Integer := 1;
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;
83 Item := Scan_Long_Long_Unsigned (Buf, Ptr'Access, Stop);
84 Check_End_Of_Field (Buf, Stop, Ptr, Width);
85 end Get_LLU;
87 -------------
88 -- Get_Uns --
89 -------------
91 procedure Get_Uns
92 (File : File_Type;
93 Item : out Unsigned;
94 Width : Field)
96 Buf : String (1 .. Field'Last);
97 Stop : Integer := 0;
98 Ptr : aliased Integer := 1;
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;
108 Item := Scan_Unsigned (Buf, Ptr'Access, Stop);
109 Check_End_Of_Field (Buf, Stop, Ptr, Width);
110 end Get_Uns;
112 --------------
113 -- Gets_LLU --
114 --------------
116 procedure Gets_LLU
117 (From : String;
118 Item : out Long_Long_Unsigned;
119 Last : out Positive)
121 Pos : aliased Integer;
123 begin
124 String_Skip (From, Pos);
125 Item := Scan_Long_Long_Unsigned (From, Pos'Access, From'Last);
126 Last := Pos - 1;
128 exception
129 when Constraint_Error =>
130 Last := Pos - 1;
131 raise Data_Error;
132 end Gets_LLU;
134 --------------
135 -- Gets_Uns --
136 --------------
138 procedure Gets_Uns
139 (From : String;
140 Item : out Unsigned;
141 Last : out Positive)
143 Pos : aliased Integer;
145 begin
146 String_Skip (From, Pos);
147 Item := Scan_Unsigned (From, Pos'Access, From'Last);
148 Last := Pos - 1;
150 exception
151 when Constraint_Error =>
152 Last := Pos - 1;
153 raise Data_Error;
154 end Gets_Uns;
156 ------------------
157 -- Load_Modular --
158 ------------------
160 procedure Load_Modular
161 (File : File_Type;
162 Buf : out String;
163 Ptr : in out Natural)
165 Hash_Loc : Natural;
166 Loaded : Boolean;
168 begin
169 Load_Skip (File);
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.
177 Load (File, Buf, Ptr, '+', '-');
178 Load_Digits (File, Buf, Ptr, Loaded);
180 if Loaded then
181 Load (File, Buf, Ptr, '#', ':', Loaded);
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;
189 Load (File, Buf, Ptr, 'E', 'e', Loaded);
191 if Loaded then
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.
198 Load (File, Buf, Ptr, '+', '-');
199 Load_Digits (File, Buf, Ptr);
200 end if;
201 end if;
202 end Load_Modular;
204 -------------
205 -- Put_LLU --
206 -------------
208 procedure Put_LLU
209 (File : File_Type;
210 Item : Long_Long_Unsigned;
211 Width : Field;
212 Base : Number_Base)
214 Buf : String (1 .. Field'Last);
215 Ptr : Natural := 0;
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;
226 Put_Item (File, Buf (1 .. Ptr));
227 end Put_LLU;
229 -------------
230 -- Put_Uns --
231 -------------
233 procedure Put_Uns
234 (File : File_Type;
235 Item : Unsigned;
236 Width : Field;
237 Base : Number_Base)
239 Buf : String (1 .. Field'Last);
240 Ptr : Natural := 0;
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;
251 Put_Item (File, Buf (1 .. Ptr));
252 end Put_Uns;
254 --------------
255 -- Puts_LLU --
256 --------------
258 procedure Puts_LLU
259 (To : out String;
260 Item : Long_Long_Unsigned;
261 Base : Number_Base)
263 Buf : String (1 .. Field'Last);
264 Ptr : Natural := 0;
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;
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;
280 --------------
281 -- Puts_Uns --
282 --------------
284 procedure Puts_Uns
285 (To : out String;
286 Item : Unsigned;
287 Base : Number_Base)
289 Buf : String (1 .. Field'Last);
290 Ptr : Natural := 0;
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;
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;
306 end Ada.Text_IO.Modular_Aux;