1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . W I D E _ W I D E _ T E X T _ I O . M O D U L A R _ A U X --
9 -- Copyright (C) 1992-2009 Free Software Foundation, Inc. --
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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada.Wide_Wide_Text_IO.Generic_Aux; use Ada.Wide_Wide_Text_IO.Generic_Aux;
34 with System.Img_BIU; use System.Img_BIU;
35 with System.Img_Uns; use System.Img_Uns;
36 with System.Img_LLB; use System.Img_LLB;
37 with System.Img_LLU; use System.Img_LLU;
38 with System.Img_LLW; use System.Img_LLW;
39 with System.Img_WIU; use System.Img_WIU;
40 with System.Val_Uns; use System.Val_Uns;
41 with System.Val_LLU; use System.Val_LLU;
43 package body Ada.Wide_Wide_Text_IO.Modular_Aux is
45 use System.Unsigned_Types;
47 -----------------------
48 -- Local Subprograms --
49 -----------------------
51 procedure Load_Modular
54 Ptr : in out Natural);
55 -- This is an auxiliary routine that is used to load an possibly signed
56 -- modular literal value from the input file into Buf, starting at Ptr + 1.
57 -- Ptr is left set to the last character stored.
65 Item : out Long_Long_Unsigned;
68 Buf : String (1 .. Field'Last);
70 Ptr : aliased Integer := 1;
74 Load_Width (File, Width, Buf, Stop);
75 String_Skip (Buf, Ptr);
77 Load_Modular (File, Buf, Stop);
80 Item := Scan_Long_Long_Unsigned (Buf, Ptr'Access, Stop);
81 Check_End_Of_Field (Buf, Stop, Ptr, Width);
93 Buf : String (1 .. Field'Last);
95 Ptr : aliased Integer := 1;
99 Load_Width (File, Width, Buf, Stop);
100 String_Skip (Buf, Ptr);
102 Load_Modular (File, Buf, Stop);
105 Item := Scan_Unsigned (Buf, Ptr'Access, Stop);
106 Check_End_Of_Field (Buf, Stop, Ptr, Width);
115 Item : out Long_Long_Unsigned;
118 Pos : aliased Integer;
121 String_Skip (From, Pos);
122 Item := Scan_Long_Long_Unsigned (From, Pos'Access, From'Last);
126 when Constraint_Error =>
139 Pos : aliased Integer;
142 String_Skip (From, Pos);
143 Item := Scan_Unsigned (From, Pos'Access, From'Last);
147 when Constraint_Error =>
155 procedure Load_Modular
158 Ptr : in out Natural)
166 -- Note: it is a bit strange to allow a minus sign here, but it seems
167 -- consistent with the general behavior expected by the ACVC tests
168 -- which is to scan past junk and then signal data error, see ACVC
169 -- test CE3704F, case (6), which is for signed integer exponents,
170 -- which seems a similar case.
172 Load (File, Buf, Ptr, '+', '-');
173 Load_Digits (File, Buf, Ptr, Loaded);
176 Load (File, Buf, Ptr, '#', ':', Loaded);
180 Load_Extended_Digits (File, Buf, Ptr);
181 Load (File, Buf, Ptr, Buf (Hash_Loc));
184 Load (File, Buf, Ptr, 'E', 'e', Loaded);
188 -- Note: it is strange to allow a minus sign, since the syntax
189 -- does not, but that is what ACVC test CE3704F, case (6) wants
190 -- for the signed case, and there seems no good reason to treat
191 -- exponents differently for the signed and unsigned cases.
193 Load (File, Buf, Ptr, '+', '-');
194 Load_Digits (File, Buf, Ptr);
205 Item : Long_Long_Unsigned;
209 Buf : String (1 .. Field'Last);
213 if Base = 10 and then Width = 0 then
214 Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
216 Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
218 Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
221 Put_Item (File, Buf (1 .. Ptr));
234 Buf : String (1 .. Field'Last);
238 if Base = 10 and then Width = 0 then
239 Set_Image_Unsigned (Item, Buf, Ptr);
241 Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
243 Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
246 Put_Item (File, Buf (1 .. Ptr));
255 Item : Long_Long_Unsigned;
258 Buf : String (1 .. Field'Last);
263 Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
265 Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
268 if Ptr > To'Length then
271 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
284 Buf : String (1 .. Field'Last);
289 Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
291 Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
294 if Ptr > To'Length then
297 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
301 end Ada.Wide_Wide_Text_IO.Modular_Aux;