1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT RUN-TIME COMPONENTS                         --
4--                                                                          --
5--               A D A . T E X T _ I O . I N T E G E R _ I O                --
6--                                                                          --
7--                                 B o d y                                  --
8--                                                                          --
9--          Copyright (C) 1992-2020, 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
32with Ada.Text_IO.Integer_Aux;
33with System.Img_BIU;  use System.Img_BIU;
34with System.Img_Int;  use System.Img_Int;
35with System.Img_LLB;  use System.Img_LLB;
36with System.Img_LLI;  use System.Img_LLI;
37with System.Img_LLW;  use System.Img_LLW;
38with System.Img_LLLB; use System.Img_LLLB;
39with System.Img_LLLI; use System.Img_LLLI;
40with System.Img_LLLW; use System.Img_LLLW;
41with System.Img_WIU;  use System.Img_WIU;
42with System.Val_Int;  use System.Val_Int;
43with System.Val_LLI;  use System.Val_LLI;
44with System.Val_LLLI; use System.Val_LLLI;
45
46package body Ada.Text_IO.Integer_IO is
47
48   package Aux_Int is new
49     Ada.Text_IO.Integer_Aux
50       (Integer,
51        Scan_Integer,
52        Set_Image_Integer,
53        Set_Image_Width_Integer,
54        Set_Image_Based_Integer);
55
56   package Aux_LLI is new
57     Ada.Text_IO.Integer_Aux
58       (Long_Long_Integer,
59        Scan_Long_Long_Integer,
60        Set_Image_Long_Long_Integer,
61        Set_Image_Width_Long_Long_Integer,
62        Set_Image_Based_Long_Long_Integer);
63
64   package Aux_LLLI is new
65     Ada.Text_IO.Integer_Aux
66       (Long_Long_Long_Integer,
67        Scan_Long_Long_Long_Integer,
68        Set_Image_Long_Long_Long_Integer,
69        Set_Image_Width_Long_Long_Long_Integer,
70        Set_Image_Based_Long_Long_Long_Integer);
71
72   Need_LLI  : constant Boolean := Num'Base'Size > Integer'Size;
73   Need_LLLI : constant Boolean := Num'Base'Size > Long_Long_Integer'Size;
74   --  Throughout this generic body, we distinguish between cases where type
75   --  Integer is acceptable, where type Long_Long_Integer is acceptable and
76   --  where type Long_Long_Long_Integer is needed. These boolean constants
77   --  are used to test for these cases and since they are constant, only code
78   --  for the relevant case will be included in the instance.
79
80   ---------
81   -- Get --
82   ---------
83
84   procedure Get
85     (File  : File_Type;
86      Item  : out Num;
87      Width : Field := 0)
88   is
89      --  We depend on a range check to get Data_Error
90
91      pragma Unsuppress (Range_Check);
92      pragma Unsuppress (Overflow_Check);
93
94   begin
95      if Need_LLLI then
96         Aux_LLLI.Get (File, Long_Long_Long_Integer (Item), Width);
97      elsif Need_LLI then
98         Aux_LLI.Get (File, Long_Long_Integer (Item), Width);
99      else
100         Aux_Int.Get (File, Integer (Item), Width);
101      end if;
102
103   exception
104      when Constraint_Error => raise Data_Error;
105   end Get;
106
107   procedure Get
108     (Item  : out Num;
109      Width : Field := 0)
110   is
111   begin
112      Get (Current_In, Item, Width);
113   end Get;
114
115   procedure Get
116     (From : String;
117      Item : out Num;
118      Last : out Positive)
119   is
120      --  We depend on a range check to get Data_Error
121
122      pragma Unsuppress (Range_Check);
123      pragma Unsuppress (Overflow_Check);
124
125   begin
126      if Need_LLLI then
127         Aux_LLLI.Gets (From, Long_Long_Long_Integer (Item), Last);
128      elsif Need_LLI then
129         Aux_LLI.Gets (From, Long_Long_Integer (Item), Last);
130      else
131         Aux_Int.Gets (From, Integer (Item), Last);
132      end if;
133
134   exception
135      when Constraint_Error => raise Data_Error;
136   end Get;
137
138   ---------
139   -- Put --
140   ---------
141
142   procedure Put
143     (File  : File_Type;
144      Item  : Num;
145      Width : Field := Default_Width;
146      Base  : Number_Base := Default_Base)
147   is
148   begin
149      if Need_LLLI then
150         Aux_LLLI.Put (File, Long_Long_Long_Integer (Item), Width, Base);
151      elsif Need_LLI then
152         Aux_LLI.Put (File, Long_Long_Integer (Item), Width, Base);
153      else
154         Aux_Int.Put (File, Integer (Item), Width, Base);
155      end if;
156   end Put;
157
158   procedure Put
159     (Item  : Num;
160      Width : Field := Default_Width;
161      Base  : Number_Base := Default_Base)
162   is
163   begin
164      Put (Current_Out, Item, Width, Base);
165   end Put;
166
167   procedure Put
168     (To   : out String;
169      Item : Num;
170      Base : Number_Base := Default_Base)
171   is
172   begin
173      if Need_LLLI then
174         Aux_LLLI.Puts (To, Long_Long_Long_Integer (Item), Base);
175      elsif Need_LLI then
176         Aux_LLI.Puts (To, Long_Long_Integer (Item), Base);
177      else
178         Aux_Int.Puts (To, Integer (Item), Base);
179      end if;
180   end Put;
181
182end Ada.Text_IO.Integer_IO;
183