Debian Codegraph @

gcc/ada/libgnat/a-ztmoio.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
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 _ 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_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_WIU; use System.Img_WIU;
39 with System.Unsigned_Types;
40 with System.Val_Uns; use System.Val_Uns;
41 with System.Val_LLU; use System.Val_LLU;
42 with System.WCh_Con; use System.WCh_Con;
43 with System.WCh_WtS; use System.WCh_WtS;
44
45 package body Ada.Wide_Wide_Text_IO.Modular_IO is
46
47 subtype Unsigned is System.Unsigned_Types.Unsigned;
48
49 package Aux_Uns is new
50 Ada.Wide_Wide_Text_IO.Integer_Aux
51 (Unsigned,
52 Scan_Unsigned,
53 Set_Image_Unsigned,
54 Set_Image_Width_Unsigned,
55 Set_Image_Based_Unsigned);
56
57 subtype Long_Long_Unsigned is System.Unsigned_Types.Long_Long_Unsigned;
58
59 package Aux_LLU is new
60 Ada.Wide_Wide_Text_IO.Integer_Aux
61 (Long_Long_Unsigned,
62 Scan_Long_Long_Unsigned,
63 Set_Image_Long_Long_Unsigned,
64 Set_Image_Width_Long_Long_Unsigned,
65 Set_Image_Based_Long_Long_Unsigned);
66
67 Need_LLU : constant Boolean := Num'Base'Size > Unsigned'Size;
68 -- Throughout this generic body, we distinguish between the case where type
69 -- Unsigned is acceptable, and where a Long_Long_Unsigned is needed. This
70 -- Boolean is used to test for these cases and since it is a constant, only
71 -- code for the relevant case will be included in the instance.
72
73 ---------
74 -- Get --
75 ---------
76
77 procedure Get
78 (File : File_Type;
79 Item : out Num;
80 Width : Field := 0)
81 is
82 -- We depend on a range check to get Data_Error
83
84 pragma Unsuppress (Range_Check);
85
86 begin
87 if Need_LLU then
88 Aux_LLU.Get (File, Long_Long_Unsigned (Item), Width);
89 else
90 Aux_Uns.Get (File, Unsigned (Item), Width);
91 end if;
92
93 exception
94 when Constraint_Error => raise Data_Error;
95 end Get;
96
97 procedure Get
98 (Item : out Num;
99 Width : Field := 0)
100 is
101 begin
102 Get (Current_In, Item, Width);
103 end Get;
104
105 procedure Get
106 (From : Wide_Wide_String;
107 Item : out Num;
108 Last : out Positive)
109 is
110 -- We depend on a range check to get Data_Error
111
112 pragma Unsuppress (Range_Check);
113
114 S : constant String := Wide_Wide_String_To_String (From, WCEM_Upper);
115 -- String on which we do the actual conversion. Note that the method
116 -- used for wide character encoding is irrelevant, since if there is
117 -- a character outside the Standard.Character range then the call to
118 -- Aux.Gets will raise Data_Error in any case.
119
120 begin
121 if Need_LLU then
122 Aux_LLU.Gets (S, Long_Long_Unsigned (Item), Last);
123 else
124 Aux_Uns.Gets (S, Unsigned (Item), Last);
125 end if;
126
127 exception
128 when Constraint_Error => raise Data_Error;
129 end Get;
130
131 ---------
132 -- Put --
133 ---------
134
135 procedure Put
136 (File : File_Type;
137 Item : Num;
138 Width : Field := Default_Width;
139 Base : Number_Base := Default_Base)
140 is
141 begin
142 if Need_LLU then
143 Aux_LLU.Put (File, Long_Long_Unsigned (Item), Width, Base);
144 else
145 Aux_Uns.Put (File, Unsigned (Item), Width, Base);
146 end if;
147 end Put;
148
149 procedure Put
150 (Item : Num;
151 Width : Field := Default_Width;
152 Base : Number_Base := Default_Base)
153 is
154 begin
155 Put (Current_Out, Item, Width, Base);
156 end Put;
157
158 procedure Put
159 (To : out Wide_Wide_String;
160 Item : Num;
161 Base : Number_Base := Default_Base)
162 is
163 S : String (To'First .. To'Last);
164
165 begin
166 if Need_LLU then
167 Aux_LLU.Puts (S, Long_Long_Unsigned (Item), Base);
168 else
169 Aux_Uns.Puts (S, Unsigned (Item), Base);
170 end if;
171
172 for J in S'Range loop
173 To (J) := Wide_Wide_Character'Val (Character'Pos (S (J)));
174 end loop;
175 end Put;
176
177 end Ada.Wide_Wide_Text_IO.Modular_IO;