* c-decl.c (duplicate_decls): Conditionalize DECL_SAVED_TREE copy.
[official-gcc.git] / gcc / ada / a-tiflau.adb
blobedd3f9c5c845b88079436149577f3ea550442dab
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . F L O A T _ A U X --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.16 $ --
10 -- --
11 -- Copyright (C) 1992-1998 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 ------------------------------------------------------------------------------
36 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
38 with System.Img_Real; use System.Img_Real;
39 with System.Val_Real; use System.Val_Real;
41 package body Ada.Text_IO.Float_Aux is
43 ---------
44 -- Get --
45 ---------
47 procedure Get
48 (File : in File_Type;
49 Item : out Long_Long_Float;
50 Width : in Field)
52 Buf : String (1 .. Field'Last);
53 Stop : Integer := 0;
54 Ptr : aliased Integer := 1;
56 begin
57 if Width /= 0 then
58 Load_Width (File, Width, Buf, Stop);
59 String_Skip (Buf, Ptr);
60 else
61 Load_Real (File, Buf, Stop);
62 end if;
64 Item := Scan_Real (Buf, Ptr'Access, Stop);
66 Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
67 end Get;
69 ----------
70 -- Gets --
71 ----------
73 procedure Gets
74 (From : in String;
75 Item : out Long_Long_Float;
76 Last : out Positive)
78 Pos : aliased Integer;
80 begin
81 String_Skip (From, Pos);
82 Item := Scan_Real (From, Pos'Access, From'Last);
83 Last := Pos - 1;
85 exception
86 when Constraint_Error =>
87 Last := Pos - 1;
88 raise Data_Error;
89 end Gets;
91 ---------------
92 -- Load_Real --
93 ---------------
95 procedure Load_Real
96 (File : in File_Type;
97 Buf : out String;
98 Ptr : in out Natural)
100 Loaded : Boolean;
102 begin
103 -- Skip initial blanks, and load possible sign
105 Load_Skip (File);
106 Load (File, Buf, Ptr, '+', '-');
108 -- Case of .nnnn
110 Load (File, Buf, Ptr, '.', Loaded);
112 if Loaded then
113 Load_Digits (File, Buf, Ptr, Loaded);
115 -- Hopeless junk if no digits loaded
117 if not Loaded then
118 return;
119 end if;
121 -- Otherwise must have digits to start
123 else
124 Load_Digits (File, Buf, Ptr, Loaded);
126 -- Hopeless junk if no digits loaded
128 if not Loaded then
129 return;
130 end if;
132 -- Based cases
134 Load (File, Buf, Ptr, '#', ':', Loaded);
136 if Loaded then
138 -- Case of nnn#.xxx#
140 Load (File, Buf, Ptr, '.', Loaded);
142 if Loaded then
143 Load_Extended_Digits (File, Buf, Ptr);
145 -- Case of nnn#xxx.[xxx]# or nnn#xxx#
147 else
148 Load_Extended_Digits (File, Buf, Ptr);
149 Load (File, Buf, Ptr, '.', Loaded);
151 if Loaded then
152 Load_Extended_Digits (File, Buf, Ptr);
153 end if;
155 -- As usual, it seems strange to allow mixed base characters,
156 -- but that is what ACVC tests expect, see CE3804M, case (3).
158 Load (File, Buf, Ptr, '#', ':');
159 end if;
161 -- Case of nnn.[nnn] or nnn
163 else
164 Load (File, Buf, Ptr, '.', Loaded);
166 if Loaded then
167 Load_Digits (File, Buf, Ptr);
168 end if;
169 end if;
170 end if;
172 -- Deal with exponent
174 Load (File, Buf, Ptr, 'E', 'e', Loaded);
176 if Loaded then
177 Load (File, Buf, Ptr, '+', '-');
178 Load_Digits (File, Buf, Ptr);
179 end if;
180 end Load_Real;
182 ---------
183 -- Put --
184 ---------
186 procedure Put
187 (File : in File_Type;
188 Item : in Long_Long_Float;
189 Fore : in Field;
190 Aft : in Field;
191 Exp : in Field)
193 Buf : String (1 .. 3 * Field'Last + 2);
194 Ptr : Natural := 0;
196 begin
197 Set_Image_Real (Item, Buf, Ptr, Fore, Aft, Exp);
198 Put_Item (File, Buf (1 .. Ptr));
199 end Put;
201 ----------
202 -- Puts --
203 ----------
205 procedure Puts
206 (To : out String;
207 Item : in Long_Long_Float;
208 Aft : in Field;
209 Exp : in Field)
211 Buf : String (1 .. 3 * Field'Last + 2);
212 Ptr : Natural := 0;
214 begin
215 Set_Image_Real (Item, Buf, Ptr, Fore => 1, Aft => Aft, Exp => Exp);
217 if Ptr > To'Length then
218 raise Layout_Error;
220 else
221 for J in 1 .. Ptr loop
222 To (To'Last - Ptr + J) := Buf (J);
223 end loop;
225 for J in To'First .. To'Last - Ptr loop
226 To (J) := ' ';
227 end loop;
228 end if;
229 end Puts;
231 end Ada.Text_IO.Float_Aux;