sem_res.adb (Resolve_Selected_Component): do not generate a discriminant check if...
[platform/upstream/gcc.git] / gcc / ada / a-timoau.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --              A D A . T E X T _ I O . M O D U L A R  _ A U X              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                            $Revision: 1.10 $
10 --                                                                          --
11 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNAT was originally developed  by the GNAT team at  New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
37
38 with System.Img_BIU; use System.Img_BIU;
39 with System.Img_Uns; use System.Img_Uns;
40 with System.Img_LLB; use System.Img_LLB;
41 with System.Img_LLU; use System.Img_LLU;
42 with System.Img_LLW; use System.Img_LLW;
43 with System.Img_WIU; use System.Img_WIU;
44 with System.Val_Uns; use System.Val_Uns;
45 with System.Val_LLU; use System.Val_LLU;
46
47 package body Ada.Text_IO.Modular_Aux is
48
49    use System.Unsigned_Types;
50
51    -----------------------
52    -- Local Subprograms --
53    -----------------------
54
55    procedure Load_Modular
56      (File : File_Type;
57       Buf  : out String;
58       Ptr  : in out Natural);
59    --  This is an auxiliary routine that is used to load an possibly signed
60    --  modular literal value from the input file into Buf, starting at Ptr + 1.
61    --  Ptr is left set to the last character stored.
62
63    -------------
64    -- Get_LLU --
65    -------------
66
67    procedure Get_LLU
68      (File  : File_Type;
69       Item  : out Long_Long_Unsigned;
70       Width : Field)
71    is
72       Buf  : String (1 .. Field'Last);
73       Stop : Integer := 0;
74       Ptr  : aliased Integer := 1;
75
76    begin
77       if Width /= 0 then
78          Load_Width (File, Width, Buf, Stop);
79          String_Skip (Buf, Ptr);
80       else
81          Load_Modular (File, Buf, Stop);
82       end if;
83
84       Item := Scan_Long_Long_Unsigned (Buf, Ptr'Access, Stop);
85       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
86    end Get_LLU;
87
88    -------------
89    -- Get_Uns --
90    -------------
91
92    procedure Get_Uns
93      (File  : File_Type;
94       Item  : out Unsigned;
95       Width : Field)
96    is
97       Buf  : String (1 .. Field'Last);
98       Stop : Integer := 0;
99       Ptr  : aliased Integer := 1;
100
101    begin
102       if Width /= 0 then
103          Load_Width (File, Width, Buf, Stop);
104          String_Skip (Buf, Ptr);
105       else
106          Load_Modular (File, Buf, Stop);
107       end if;
108
109       Item := Scan_Unsigned (Buf, Ptr'Access, Stop);
110       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
111    end Get_Uns;
112
113    --------------
114    -- Gets_LLU --
115    --------------
116
117    procedure Gets_LLU
118      (From : String;
119       Item : out Long_Long_Unsigned;
120       Last : out Positive)
121    is
122       Pos : aliased Integer;
123
124    begin
125       String_Skip (From, Pos);
126       Item := Scan_Long_Long_Unsigned (From, Pos'Access, From'Last);
127       Last := Pos - 1;
128
129    exception
130       when Constraint_Error =>
131          Last := Pos - 1;
132          raise Data_Error;
133    end Gets_LLU;
134
135    --------------
136    -- Gets_Uns --
137    --------------
138
139    procedure Gets_Uns
140      (From : String;
141       Item : out Unsigned;
142       Last : out Positive)
143    is
144       Pos : aliased Integer;
145
146    begin
147       String_Skip (From, Pos);
148       Item := Scan_Unsigned (From, Pos'Access, From'Last);
149       Last := Pos - 1;
150
151    exception
152       when Constraint_Error =>
153          Last := Pos - 1;
154          raise Data_Error;
155    end Gets_Uns;
156
157    ------------------
158    -- Load_Modular --
159    ------------------
160
161    procedure Load_Modular
162      (File : File_Type;
163       Buf  : out String;
164       Ptr  : in out Natural)
165    is
166       Hash_Loc : Natural;
167       Loaded   : Boolean;
168
169    begin
170       Load_Skip (File);
171
172       --  Note: it is a bit strange to allow a minus sign here, but it seems
173       --  consistent with the general behavior expected by the ACVC tests
174       --  which is to scan past junk and then signal data error, see ACVC
175       --  test CE3704F, case (6), which is for signed integer exponents,
176       --  which seems a similar case.
177
178       Load (File, Buf, Ptr, '+', '-');
179       Load_Digits (File, Buf, Ptr, Loaded);
180
181       if Loaded then
182          Load (File, Buf, Ptr, '#', ':', Loaded);
183
184          if Loaded then
185             Hash_Loc := Ptr;
186             Load_Extended_Digits (File, Buf, Ptr);
187             Load (File, Buf, Ptr, Buf (Hash_Loc));
188          end if;
189
190          Load (File, Buf, Ptr, 'E', 'e', Loaded);
191
192          if Loaded then
193
194             --  Note: it is strange to allow a minus sign, since the syntax
195             --  does not, but that is what ACVC test CE3704F, case (6) wants
196             --  for the signed case, and there seems no good reason to treat
197             --  exponents differently for the signed and unsigned cases.
198
199             Load (File, Buf, Ptr, '+', '-');
200             Load_Digits (File, Buf, Ptr);
201          end if;
202       end if;
203    end Load_Modular;
204
205    -------------
206    -- Put_LLU --
207    -------------
208
209    procedure Put_LLU
210      (File  : File_Type;
211       Item  : Long_Long_Unsigned;
212       Width : Field;
213       Base  : Number_Base)
214    is
215       Buf : String (1 .. Field'Last);
216       Ptr : Natural := 0;
217
218    begin
219       if Base = 10 and then Width = 0 then
220          Set_Image_Long_Long_Unsigned (Item, Buf, Ptr);
221       elsif Base = 10 then
222          Set_Image_Width_Long_Long_Unsigned (Item, Width, Buf, Ptr);
223       else
224          Set_Image_Based_Long_Long_Unsigned (Item, Base, Width, Buf, Ptr);
225       end if;
226
227       Put_Item (File, Buf (1 .. Ptr));
228    end Put_LLU;
229
230    -------------
231    -- Put_Uns --
232    -------------
233
234    procedure Put_Uns
235      (File  : File_Type;
236       Item  : Unsigned;
237       Width : Field;
238       Base  : Number_Base)
239    is
240       Buf : String (1 .. Field'Last);
241       Ptr : Natural := 0;
242
243    begin
244       if Base = 10 and then Width = 0 then
245          Set_Image_Unsigned (Item, Buf, Ptr);
246       elsif Base = 10 then
247          Set_Image_Width_Unsigned (Item, Width, Buf, Ptr);
248       else
249          Set_Image_Based_Unsigned (Item, Base, Width, Buf, Ptr);
250       end if;
251
252       Put_Item (File, Buf (1 .. Ptr));
253    end Put_Uns;
254
255    --------------
256    -- Puts_LLU --
257    --------------
258
259    procedure Puts_LLU
260      (To   : out String;
261       Item : Long_Long_Unsigned;
262       Base : Number_Base)
263    is
264       Buf : String (1 .. Field'Last);
265       Ptr : Natural := 0;
266
267    begin
268       if Base = 10 then
269          Set_Image_Width_Long_Long_Unsigned (Item, To'Length, Buf, Ptr);
270       else
271          Set_Image_Based_Long_Long_Unsigned (Item, Base, To'Length, Buf, Ptr);
272       end if;
273
274       if Ptr > To'Length then
275          raise Layout_Error;
276       else
277          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
278       end if;
279    end Puts_LLU;
280
281    --------------
282    -- Puts_Uns --
283    --------------
284
285    procedure Puts_Uns
286      (To   : out String;
287       Item : Unsigned;
288       Base : Number_Base)
289    is
290       Buf : String (1 .. Field'Last);
291       Ptr : Natural := 0;
292
293    begin
294       if Base = 10 then
295          Set_Image_Width_Unsigned (Item, To'Length, Buf, Ptr);
296       else
297          Set_Image_Based_Unsigned (Item, Base, To'Length, Buf, Ptr);
298       end if;
299
300       if Ptr > To'Length then
301          raise Layout_Error;
302       else
303          To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
304       end if;
305    end Puts_Uns;
306
307 end Ada.Text_IO.Modular_Aux;