Debian Codegraph @

gcc/ada/libgnat/a-wtmoio__128.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . W I D E _ T E X T _ I O . M O D U L A R _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, 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 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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with Ada.Wide_Text_IO.Integer_Aux;
33 with System.Img_BIU; use System.Img_BIU;
34 with System.Img_Uns; use System.Img_Uns;
35 with System.Img_LLB; use System.Img_LLB;
36 with System.Img_LLU; use System.Img_LLU;
37 with System.Img_LLW; use System.Img_LLW;
38 with System.Img_LLLB; use System.Img_LLLB;
39 with System.Img_LLLU; use System.Img_LLLU;
40 with System.Img_LLLW; use System.Img_LLLW;
41 with System.Img_WIU; use System.Img_WIU;
42 with System.Unsigned_Types;
43 with System.Val_Uns; use System.Val_Uns;
44 with System.Val_LLU; use System.Val_LLU;
45 with System.Val_LLLU; use System.Val_LLLU;
46 with System.WCh_Con; use System.WCh_Con;
47 with System.WCh_WtS; use System.WCh_WtS;
48
49 package body Ada.Wide_Text_IO.Modular_IO is
50
51 subtype Unsigned is System.Unsigned_Types.Unsigned;
52
53 package Aux_Uns is new
54 Ada.Wide_Text_IO.Integer_Aux
55 (Unsigned,
56 Scan_Unsigned,
57 Set_Image_Unsigned,
58 Set_Image_Width_Unsigned,
59 Set_Image_Based_Unsigned);
60
61 subtype Long_Long_Unsigned is System.Unsigned_Types.Long_Long_Unsigned;
62
63 package Aux_LLU is new
64 Ada.Wide_Text_IO.Integer_Aux
65 (Long_Long_Unsigned,
66 Scan_Long_Long_Unsigned,
67 Set_Image_Long_Long_Unsigned,
68 Set_Image_Width_Long_Long_Unsigned,
69 Set_Image_Based_Long_Long_Unsigned);
70
71 subtype Long_Long_Long_Unsigned is
72 System.Unsigned_Types.Long_Long_Long_Unsigned;
73
74 package Aux_LLLU is new
75 Ada.Wide_Text_IO.Integer_Aux
76 (Long_Long_Long_Unsigned,
77 Scan_Long_Long_Long_Unsigned,
78 Set_Image_Long_Long_Long_Unsigned,
79 Set_Image_Width_Long_Long_Long_Unsigned,
80 Set_Image_Based_Long_Long_Long_Unsigned);
81
82 Need_LLU : constant Boolean := Num'Base'Size > Unsigned'Size;
83 Need_LLLU : constant Boolean := Num'Base'Size > Long_Long_Unsigned'Size;
84 -- Throughout this generic body, we distinguish between cases where type
85 -- Unsigned is acceptable, where type Long_Long_Unsigned is acceptable and
86 -- where type Long_Long_Long_Unsigned is needed. These boolean constants
87 -- are used to test for these cases and since they are constant, only code
88 -- for the relevant case will be included in the instance.
89
90 ---------
91 -- Get --
92 ---------
93
94 procedure Get
95 (File : File_Type;
96 Item : out Num;
97 Width : Field := 0)
98 is
99 -- We depend on a range check to get Data_Error
100
101 pragma Unsuppress (Range_Check);
102
103 begin
104 if Need_LLLU then
105 Aux_LLLU.Get (File, Long_Long_Long_Unsigned (Item), Width);
106 elsif Need_LLU then
107 Aux_LLU.Get (File, Long_Long_Unsigned (Item), Width);
108 else
109 Aux_Uns.Get (File, Unsigned (Item), Width);
110 end if;
111
112 exception
113 when Constraint_Error => raise Data_Error;
114 end Get;
115
116 procedure Get
117 (Item : out Num;
118 Width : Field := 0)
119 is
120 begin
121 Get (Current_In, Item, Width);
122 end Get;
123
124 procedure Get
125 (From : Wide_String;
126 Item : out Num;
127 Last : out Positive)
128 is
129 -- We depend on a range check to get Data_Error
130
131 pragma Unsuppress (Range_Check);
132
133 S : constant String := Wide_String_To_String (From, WCEM_Upper);
134 -- String on which we do the actual conversion. Note that the method
135 -- used for wide character encoding is irrelevant, since if there is
136 -- a character outside the Standard.Character range then the call to
137 -- Aux.Gets will raise Data_Error in any case.
138
139 begin
140 if Need_LLLU then
141 Aux_LLLU.Gets (S, Long_Long_Long_Unsigned (Item), Last);
142 elsif Need_LLU then
143 Aux_LLU.Gets (S, Long_Long_Unsigned (Item), Last);
144 else
145 Aux_Uns.Gets (S, Unsigned (Item), Last);
146 end if;
147
148 exception
149 when Constraint_Error => raise Data_Error;
150 end Get;
151
152 ---------
153 -- Put --
154 ---------
155
156 procedure Put
157 (File : File_Type;
158 Item : Num;
159 Width : Field := Default_Width;
160 Base : Number_Base := Default_Base)
161 is
162 begin
163 if Need_LLLU then
164 Aux_LLLU.Put (File, Long_Long_Long_Unsigned (Item), Width, Base);
165 elsif Need_LLU then
166 Aux_LLU.Put (File, Long_Long_Unsigned (Item), Width, Base);
167 else
168 Aux_Uns.Put (File, Unsigned (Item), Width, Base);
169 end if;
170 end Put;
171
172 procedure Put
173 (Item : Num;
174 Width : Field := Default_Width;
175 Base : Number_Base := Default_Base)
176 is
177 begin
178 Put (Current_Out, Item, Width, Base);
179 end Put;
180
181 procedure Put
182 (To : out Wide_String;
183 Item : Num;
184 Base : Number_Base := Default_Base)
185 is
186 S : String (To'First .. To'Last);
187
188 begin
189 if Need_LLLU then
190 Aux_LLLU.Puts (S, Long_Long_Long_Unsigned (Item), Base);
191 elsif Need_LLU then
192 Aux_LLU.Puts (S, Long_Long_Unsigned (Item), Base);
193 else
194 Aux_Uns.Puts (S, Unsigned (Item), Base);
195 end if;
196
197 for J in S'Range loop
198 To (J) := Wide_Character'Val (Character'Pos (S (J)));
199 end loop;
200 end Put;
201
202 end Ada.Wide_Text_IO.Modular_IO;