Debian Codegraph @

gcc/ada/libgnat/a-tideio.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . D E C I M A L _ 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 Interfaces;
33 with Ada.Text_IO.Decimal_Aux;
34 with System.Img_Decimal_32; use System.Img_Decimal_32;
35 with System.Img_Decimal_64; use System.Img_Decimal_64;
36 with System.Val_Decimal_32; use System.Val_Decimal_32;
37 with System.Val_Decimal_64; use System.Val_Decimal_64;
38
39 package body Ada.Text_IO.Decimal_IO is
40
41 subtype Int32 is Interfaces.Integer_32;
42 subtype Int64 is Interfaces.Integer_64;
43
44 package Aux32 is new
45 Ada.Text_IO.Decimal_Aux
46 (Int32,
47 Scan_Decimal32,
48 Set_Image_Decimal32);
49
50 package Aux64 is new
51 Ada.Text_IO.Decimal_Aux
52 (Int64,
53 Scan_Decimal64,
54 Set_Image_Decimal64);
55
56 Need64 : constant Boolean := Num'Size > 32;
57 -- Throughout this generic body, we distinguish between the case where type
58 -- Int32 is acceptable and where type Int64 is needed. This Boolean is used
59 -- to test for these cases and since it is a constant, only code for the
60 -- relevant case will be included in the instance.
61
62 Scale : constant Integer := Num'Scale;
63
64 ---------
65 -- Get --
66 ---------
67
68 procedure Get
69 (File : File_Type;
70 Item : out Num;
71 Width : Field := 0)
72 is
73 pragma Unsuppress (Range_Check);
74
75 begin
76 if Need64 then
77 Item := Num'Fixed_Value (Aux64.Get (File, Width, Scale));
78 else
79 Item := Num'Fixed_Value (Aux32.Get (File, Width, Scale));
80 end if;
81
82 exception
83 when Constraint_Error => raise Data_Error;
84 end Get;
85
86 procedure Get
87 (Item : out Num;
88 Width : Field := 0)
89 is
90 begin
91 Get (Current_In, Item, Width);
92 end Get;
93
94 procedure Get
95 (From : String;
96 Item : out Num;
97 Last : out Positive)
98 is
99 pragma Unsuppress (Range_Check);
100
101 begin
102 if Need64 then
103 Item := Num'Fixed_Value (Aux64.Gets (From, Last, Scale));
104 else
105 Item := Num'Fixed_Value (Aux32.Gets (From, Last, Scale));
106 end if;
107
108 exception
109 when Constraint_Error => raise Data_Error;
110 end Get;
111
112 ---------
113 -- Put --
114 ---------
115
116 procedure Put
117 (File : File_Type;
118 Item : Num;
119 Fore : Field := Default_Fore;
120 Aft : Field := Default_Aft;
121 Exp : Field := Default_Exp)
122 is
123 begin
124 if Need64 then
125 Aux64.Put
126 (File, Int64'Integer_Value (Item), Fore, Aft, Exp, Scale);
127 else
128 Aux32.Put
129 (File, Int32'Integer_Value (Item), Fore, Aft, Exp, Scale);
130 end if;
131 end Put;
132
133 procedure Put
134 (Item : Num;
135 Fore : Field := Default_Fore;
136 Aft : Field := Default_Aft;
137 Exp : Field := Default_Exp)
138 is
139 begin
140 Put (Current_Out, Item, Fore, Aft, Exp);
141 end Put;
142
143 procedure Put
144 (To : out String;
145 Item : Num;
146 Aft : Field := Default_Aft;
147 Exp : Field := Default_Exp)
148 is
149 begin
150 if Need64 then
151 Aux64.Puts (To, Int64'Integer_Value (Item), Aft, Exp, Scale);
152 else
153 Aux32.Puts (To, Int32'Integer_Value (Item), Aft, Exp, Scale);
154 end if;
155 end Put;
156
157 end Ada.Text_IO.Decimal_IO;