| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- A D A . 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.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 |
|
| 47 |
package body Ada.Text_IO.Modular_IO is |
| 48 |
|
| 49 |
subtype Unsigned is System.Unsigned_Types.Unsigned; |
| 50 |
|
| 51 |
package Aux_Uns is new |
| 52 |
Ada.Text_IO.Integer_Aux |
| 53 |
(Unsigned, |
| 54 |
Scan_Unsigned, |
| 55 |
Set_Image_Unsigned, |
| 56 |
Set_Image_Width_Unsigned, |
| 57 |
Set_Image_Based_Unsigned); |
| 58 |
|
| 59 |
subtype Long_Long_Unsigned is System.Unsigned_Types.Long_Long_Unsigned; |
| 60 |
|
| 61 |
package Aux_LLU is new |
| 62 |
Ada.Text_IO.Integer_Aux |
| 63 |
(Long_Long_Unsigned, |
| 64 |
Scan_Long_Long_Unsigned, |
| 65 |
Set_Image_Long_Long_Unsigned, |
| 66 |
Set_Image_Width_Long_Long_Unsigned, |
| 67 |
Set_Image_Based_Long_Long_Unsigned); |
| 68 |
|
| 69 |
subtype Long_Long_Long_Unsigned is |
| 70 |
System.Unsigned_Types.Long_Long_Long_Unsigned; |
| 71 |
|
| 72 |
package Aux_LLLU is new |
| 73 |
Ada.Text_IO.Integer_Aux |
| 74 |
(Long_Long_Long_Unsigned, |
| 75 |
Scan_Long_Long_Long_Unsigned, |
| 76 |
Set_Image_Long_Long_Long_Unsigned, |
| 77 |
Set_Image_Width_Long_Long_Long_Unsigned, |
| 78 |
Set_Image_Based_Long_Long_Long_Unsigned); |
| 79 |
|
| 80 |
Need_LLU : constant Boolean := Num'Base'Size > Unsigned'Size; |
| 81 |
Need_LLLU : constant Boolean := Num'Base'Size > Long_Long_Unsigned'Size; |
| 82 |
-- Throughout this generic body, we distinguish between cases where type |
| 83 |
-- Unsigned is acceptable, where type Long_Long_Unsigned is acceptable and |
| 84 |
-- where type Long_Long_Long_Unsigned is needed. These boolean constants |
| 85 |
-- are used to test for these cases and since they are constant, only code |
| 86 |
-- for the relevant case will be included in the instance. |
| 87 |
|
| 88 |
--------- |
| 89 |
-- Get -- |
| 90 |
--------- |
| 91 |
|
| 92 |
procedure Get |
| 93 |
(File : File_Type; |
| 94 |
Item : out Num; |
| 95 |
Width : Field := 0) |
| 96 |
is |
| 97 |
-- We depend on a range check to get Data_Error |
| 98 |
|
| 99 |
pragma Unsuppress (Range_Check); |
| 100 |
|
| 101 |
begin |
| 102 |
if Need_LLLU then |
| 103 |
Aux_LLLU.Get (File, Long_Long_Long_Unsigned (Item), Width); |
| 104 |
elsif Need_LLU then |
| 105 |
Aux_LLU.Get (File, Long_Long_Unsigned (Item), Width); |
| 106 |
else |
| 107 |
Aux_Uns.Get (File, Unsigned (Item), Width); |
| 108 |
end if; |
| 109 |
|
| 110 |
exception |
| 111 |
when Constraint_Error => raise Data_Error; |
| 112 |
end Get; |
| 113 |
|
| 114 |
procedure Get |
| 115 |
(Item : out Num; |
| 116 |
Width : Field := 0) |
| 117 |
is |
| 118 |
begin |
| 119 |
Get (Current_In, Item, Width); |
| 120 |
end Get; |
| 121 |
|
| 122 |
procedure Get |
| 123 |
(From : String; |
| 124 |
Item : out Num; |
| 125 |
Last : out Positive) |
| 126 |
is |
| 127 |
-- We depend on a range check to get Data_Error |
| 128 |
|
| 129 |
pragma Unsuppress (Range_Check); |
| 130 |
|
| 131 |
begin |
| 132 |
if Need_LLLU then |
| 133 |
Aux_LLLU.Gets (From, Long_Long_Long_Unsigned (Item), Last); |
| 134 |
elsif Need_LLU then |
| 135 |
Aux_LLU.Gets (From, Long_Long_Unsigned (Item), Last); |
| 136 |
else |
| 137 |
Aux_Uns.Gets (From, Unsigned (Item), Last); |
| 138 |
end if; |
| 139 |
|
| 140 |
exception |
| 141 |
when Constraint_Error => raise Data_Error; |
| 142 |
end Get; |
| 143 |
|
| 144 |
--------- |
| 145 |
-- Put -- |
| 146 |
--------- |
| 147 |
|
| 148 |
procedure Put |
| 149 |
(File : File_Type; |
| 150 |
Item : Num; |
| 151 |
Width : Field := Default_Width; |
| 152 |
Base : Number_Base := Default_Base) |
| 153 |
is |
| 154 |
begin |
| 155 |
if Need_LLLU then |
| 156 |
Aux_LLLU.Put (File, Long_Long_Long_Unsigned (Item), Width, Base); |
| 157 |
elsif Need_LLU then |
| 158 |
Aux_LLU.Put (File, Long_Long_Unsigned (Item), Width, Base); |
| 159 |
else |
| 160 |
Aux_Uns.Put (File, Unsigned (Item), Width, Base); |
| 161 |
end if; |
| 162 |
end Put; |
| 163 |
|
| 164 |
procedure Put |
| 165 |
(Item : Num; |
| 166 |
Width : Field := Default_Width; |
| 167 |
Base : Number_Base := Default_Base) |
| 168 |
is |
| 169 |
begin |
| 170 |
Put (Current_Out, Item, Width, Base); |
| 171 |
end Put; |
| 172 |
|
| 173 |
procedure Put |
| 174 |
(To : out String; |
| 175 |
Item : Num; |
| 176 |
Base : Number_Base := Default_Base) |
| 177 |
is |
| 178 |
begin |
| 179 |
if Need_LLLU then |
| 180 |
Aux_LLLU.Puts (To, Long_Long_Long_Unsigned (Item), Base); |
| 181 |
elsif Need_LLU then |
| 182 |
Aux_LLU.Puts (To, Long_Long_Unsigned (Item), Base); |
| 183 |
else |
| 184 |
Aux_Uns.Puts (To, Unsigned (Item), Base); |
| 185 |
end if; |
| 186 |
end Put; |
| 187 |
|
| 188 |
end Ada.Text_IO.Modular_IO; |