]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/a-wtmoau.adb
3psoccon.ads, [...]: Files added.
[thirdparty/gcc.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 -- Copyright (C) 1992-2003 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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_Uns; use System.Img_Uns;
38 with System.Img_LLB; use System.Img_LLB;
39 with System.Img_LLU; use System.Img_LLU;
40 with System.Img_LLW; use System.Img_LLW;
41 with System.Img_WIU; use System.Img_WIU;
42 with System.Val_Uns; use System.Val_Uns;
43 with System.Val_LLU; use System.Val_LLU;
44
45 package body Ada.Wide_Text_IO.Modular_Aux is
46
47 use System.Unsigned_Types;
48
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
52
53 procedure Load_Modular
54 (File : in File_Type;
55 Buf : out String;
56 Ptr : in out Natural);
57 -- This is an auxiliary routine that is used to load an possibly signed
58 -- modular literal value from the input file into Buf, starting at Ptr + 1.
59 -- Ptr is left set to the last character stored.
60
61 -------------
62 -- Get_LLU --
63 -------------
64
65 procedure Get_LLU
66 (File : in File_Type;
67 Item : out Long_Long_Unsigned;
68 Width : in Field)
69 is
70 Buf : String (1 .. Field'Last);
71 Stop : Integer := 0;
72 Ptr : aliased Integer := 1;
73
74 begin
75 if Width /= 0 then
76 Load_Width (File, Width, Buf, Stop);
77 String_Skip (Buf, Ptr);
78 else
79 Load_Modular (File, Buf, Stop);
80 end if;
81
82 Item := Scan_Long_Long_Unsigned (Buf, Ptr'Access, Stop);
83 Check_End_Of_Field (Buf, Stop, Ptr, Width);
84 end Get_LLU;
85
86 -------------
87 -- Get_Uns --
88 -------------
89
90 procedure Get_Uns
91 (File : in File_Type;
92 Item : out Unsigned;
93 Width : in Field)
94 is
95 Buf : String (1 .. Field'Last);
96 Stop : Integer := 0;
97 Ptr : aliased Integer := 1;
98
99 begin
100 if Width /= 0 then
101 Load_Width (File, Width, Buf, Stop);
102 String_Skip (Buf, Ptr);
103 else
104 Load_Modular (File, Buf, Stop);
105 end if;
106
107 Item := Scan_Unsigned (Buf, Ptr'Access, Stop);
108 Check_End_Of_Field (Buf, Stop, Ptr, Width);
109 end Get_Uns;
110
111 --------------
112 -- Gets_LLU --
113 --------------
114
115 procedure Gets_LLU
116 (From : in String;
117 Item : out Long_Long_Unsigned;
118 Last : out Positive)
119 is
120 Pos : aliased Integer;
121
122 begin
123 String_Skip (From, Pos);
124 Item := Scan_Long_Long_Unsigned (From, Pos'Access, From'Last);
125 Last := Pos - 1;
126
127 exception
128 when Constraint_Error =>
129 raise Data_Error;
130 end Gets_LLU;
131
132 --------------
133 -- Gets_Uns --
134 --------------
135
136 procedure Gets_Uns
137 (From : in String;
138 Item : out Unsigned;
139 Last : out Positive)
140 is
141 Pos : aliased Integer;
142
143 begin
144 String_Skip (From, Pos);
145 Item := Scan_Unsigned (From, Pos'Access, From'Last);
146 Last := Pos - 1;
147
148 exception
149 when Constraint_Error =>
150 raise Data_Error;
151 end Gets_Uns;
152
153 ------------------
154 -- Load_Modular --
155 ------------------
156
157 procedure Load_Modular
158 (File : in File_Type;
159 Buf : out String;
160 Ptr : in out Natural)
161 is
162 Hash_Loc : Natural;
163 Loaded : Boolean;
164
165 begin
166 Load_Skip (File);
167
168 -- Note: it is a bit strange to allow a minus sign here, but it seems
169 -- consistent with the general behavior expected by the ACVC tests
170 -- which is to scan past junk and then signal data error, see ACVC
171 -- test CE3704F, case (6), which is for signed integer exponents,
172 -- which seems a similar case.
173
174 Load (File, Buf, Ptr, '+', '-');
175 Load_Digits (File, Buf, Ptr, Loaded);
176
177 if Loaded then
178 Load (File, Buf, Ptr, '#', ':', Loaded);
179
180 if Loaded then
181 Hash_Loc := Ptr;
182 Load_Extended_Digits (File, Buf, Ptr);
183 Load (File, Buf, Ptr, Buf (Hash_Loc));
184 end if;
185
186 Load (File, Buf, Ptr, 'E', 'e', Loaded);
187
188 if Loaded then
189
190 -- Note: it is strange to allow a minus sign, since the syntax
191 -- does not, but that is what ACVC test CE3704F, case (6) wants
192 -- for the signed case, and there seems no good reason to treat
193 -- exponents differently for the signed and unsigned cases.
194
195 Load (File, Buf, Ptr, '+', '-');
196 Load_Digits (File, Buf, Ptr);
197 end if;
198 end if;
199 end Load_Modular;
200
201 -------------
202 -- Put_LLU --
203 -------------
204
205 procedure Put_LLU
206 (File : in File_Type;
207 Item : in Long_Long_Unsigned;
208 Width : in Field;
209 Base : in Number_Base)
210 is
211 Buf : String (1 .. Field'Last);
212 Ptr : Natural := 0;
213
214 begin
215 if Base = 10 and then Width = 0 then
216 Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
217 elsif Base = 10 then
218 Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
219 else
220 Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
221 end if;
222
223 Put_Item (File, Buf (1 .. Ptr));
224 end Put_LLU;
225
226 -------------
227 -- Put_Uns --
228 -------------
229
230 procedure Put_Uns
231 (File : in File_Type;
232 Item : in Unsigned;
233 Width : in Field;
234 Base : in Number_Base)
235 is
236 Buf : String (1 .. Field'Last);
237 Ptr : Natural := 0;
238
239 begin
240 if Base = 10 and then Width = 0 then
241 Set_Image_Unsigned (Item, Buf, Ptr);
242 elsif Base = 10 then
243 Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
244 else
245 Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
246 end if;
247
248 Put_Item (File, Buf (1 .. Ptr));
249 end Put_Uns;
250
251 --------------
252 -- Puts_LLU --
253 --------------
254
255 procedure Puts_LLU
256 (To : out String;
257 Item : in Long_Long_Unsigned;
258 Base : in Number_Base)
259 is
260 Buf : String (1 .. Field'Last);
261 Ptr : Natural := 0;
262
263 begin
264 if Base = 10 then
265 Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
266 else
267 Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
268 end if;
269
270 if Ptr > To'Length then
271 raise Layout_Error;
272 else
273 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
274 end if;
275 end Puts_LLU;
276
277 --------------
278 -- Puts_Uns --
279 --------------
280
281 procedure Puts_Uns
282 (To : out String;
283 Item : in Unsigned;
284 Base : in Number_Base)
285 is
286 Buf : String (1 .. Field'Last);
287 Ptr : Natural := 0;
288
289 begin
290 if Base = 10 then
291 Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
292 else
293 Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
294 end if;
295
296 if Ptr > To'Length then
297 raise Layout_Error;
298 else
299 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
300 end if;
301 end Puts_Uns;
302
303 end Ada.Wide_Text_IO.Modular_Aux;