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-2014, 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);
177 -- Deal with based case. We recognize either the standard '#' or the
178 -- allowed alternative replacement ':' (see RM J.2(3)).
180 Load (File, Buf, Ptr, '#', ':', Loaded);
184 Load_Extended_Digits (File, Buf, Ptr);
185 Load (File, Buf, Ptr, Buf (Hash_Loc));
188 Load (File, Buf, Ptr, 'E', 'e', Loaded);
192 -- Note: it is strange to allow a minus sign, since the syntax
193 -- does not, but that is what ACVC test CE3704F, case (6) wants
194 -- for the signed case, and there seems no good reason to treat
195 -- exponents differently for the signed and unsigned cases.
197 Load (File, Buf, Ptr, '+', '-');
198 Load_Digits (File, Buf, Ptr);
209 Item : Long_Long_Unsigned;
213 Buf : String (1 .. Field'Last);
217 if Base = 10 and then Width = 0 then
218 Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
220 Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
222 Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
225 Put_Item (File, Buf (1 .. Ptr));
238 Buf : String (1 .. Field'Last);
242 if Base = 10 and then Width = 0 then
243 Set_Image_Unsigned (Item, Buf, Ptr);
245 Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
247 Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
250 Put_Item (File, Buf (1 .. Ptr));
259 Item : Long_Long_Unsigned;
262 Buf : String (1 .. Field'Last);
267 Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
269 Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
272 if Ptr > To'Length then
275 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
288 Buf : String (1 .. Field'Last);
293 Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
295 Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
298 if Ptr > To'Length then
301 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
305 end Ada.Wide_Wide_Text_IO.Modular_Aux;