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_WIU; use System.Img_WIU;
39with System.Val_Int; use System.Val_Int;
40with System.Val_LLI; use System.Val_LLI;
41
42package body Ada.Text_IO.Integer_IO is
43
44   package Aux_Int is new
45     Ada.Text_IO.Integer_Aux
46       (Integer,
47        Scan_Integer,
48        Set_Image_Integer,
49        Set_Image_Width_Integer,
50        Set_Image_Based_Integer);
51
52   package Aux_LLI is new
53     Ada.Text_IO.Integer_Aux
54       (Long_Long_Integer,
55        Scan_Long_Long_Integer,
56        Set_Image_Long_Long_Integer,
57        Set_Image_Width_Long_Long_Integer,
58        Set_Image_Based_Long_Long_Integer);
59
60   Need_LLI : constant Boolean := Num'Base'Size > Integer'Size;
61   --  Throughout this generic body, we distinguish between the case where type
62   --  Integer is acceptable, and where a Long_Long_Integer is needed. This
63   --  Boolean is used to test for these cases and since it is a constant, only
64   --  code for the relevant case will be included in the instance.
65
66   ---------
67   -- Get --
68   ---------
69
70   procedure Get
71     (File  : File_Type;
72      Item  : out Num;
73      Width : Field := 0)
74   is
75      --  We depend on a range check to get Data_Error
76
77      pragma Unsuppress (Range_Check);
78      pragma Unsuppress (Overflow_Check);
79
80   begin
81      if Need_LLI then
82         Aux_LLI.Get (File, Long_Long_Integer (Item), Width);
83      else
84         Aux_Int.Get (File, Integer (Item), Width);
85      end if;
86
87   exception
88      when Constraint_Error => raise Data_Error;
89   end Get;
90
91   procedure Get
92     (Item  : out Num;
93      Width : Field := 0)
94   is
95   begin
96      Get (Current_In, Item, Width);
97   end Get;
98
99   procedure Get
100     (From : String;
101      Item : out Num;
102      Last : out Positive)
103   is
104      --  We depend on a range check to get Data_Error
105
106      pragma Unsuppress (Range_Check);
107      pragma Unsuppress (Overflow_Check);
108
109   begin
110      if Need_LLI then
111         Aux_LLI.Gets (From, Long_Long_Integer (Item), Last);
112      else
113         Aux_Int.Gets (From, Integer (Item), Last);
114      end if;
115
116   exception
117      when Constraint_Error => raise Data_Error;
118   end Get;
119
120   ---------
121   -- Put --
122   ---------
123
124   procedure Put
125     (File  : File_Type;
126      Item  : Num;
127      Width : Field := Default_Width;
128      Base  : Number_Base := Default_Base)
129   is
130   begin
131      if Need_LLI then
132         Aux_LLI.Put (File, Long_Long_Integer (Item), Width, Base);
133      else
134         Aux_Int.Put (File, Integer (Item), Width, Base);
135      end if;
136   end Put;
137
138   procedure Put
139     (Item  : Num;
140      Width : Field := Default_Width;
141      Base  : Number_Base := Default_Base)
142   is
143   begin
144      Put (Current_Out, Item, Width, Base);
145   end Put;
146
147   procedure Put
148     (To   : out String;
149      Item : Num;
150      Base : Number_Base := Default_Base)
151   is
152   begin
153      if Need_LLI then
154         Aux_LLI.Puts (To, Long_Long_Integer (Item), Base);
155      else
156         Aux_Int.Puts (To, Integer (Item), Base);
157      end if;
158   end Put;
159
160end Ada.Text_IO.Integer_IO;
161