final.c: Use rtx_sequence
[official-gcc.git] / gcc / ada / a-ticoau.adb
blob0601ef064f079eb5cd4cc2ead136bcfad728085c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . C O M P L E X _ A U X --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2009, 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 ------------------------------------------------------------------------------
32 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
33 with Ada.Text_IO.Float_Aux;
35 with System.Img_Real; use System.Img_Real;
37 package body Ada.Text_IO.Complex_Aux is
39 package Aux renames Ada.Text_IO.Float_Aux;
41 ---------
42 -- Get --
43 ---------
45 procedure Get
46 (File : File_Type;
47 ItemR : out Long_Long_Float;
48 ItemI : out Long_Long_Float;
49 Width : Field)
51 Buf : String (1 .. Field'Last);
52 Stop : Integer := 0;
53 Ptr : aliased Integer;
54 Paren : Boolean := False;
56 begin
57 -- General note for following code, exceptions from the calls to
58 -- Get for components of the complex value are propagated.
60 if Width /= 0 then
61 Load_Width (File, Width, Buf, Stop);
62 Gets (Buf (1 .. Stop), ItemR, ItemI, Ptr);
64 for J in Ptr + 1 .. Stop loop
65 if not Is_Blank (Buf (J)) then
66 raise Data_Error;
67 end if;
68 end loop;
70 -- Case of width = 0
72 else
73 Load_Skip (File);
74 Ptr := 0;
75 Load (File, Buf, Ptr, '(', Paren);
76 Aux.Get (File, ItemR, 0);
77 Load_Skip (File);
78 Load (File, Buf, Ptr, ',');
79 Aux.Get (File, ItemI, 0);
81 if Paren then
82 Load_Skip (File);
83 Load (File, Buf, Ptr, ')', Paren);
85 if not Paren then
86 raise Data_Error;
87 end if;
88 end if;
89 end if;
90 end Get;
92 ----------
93 -- Gets --
94 ----------
96 procedure Gets
97 (From : String;
98 ItemR : out Long_Long_Float;
99 ItemI : out Long_Long_Float;
100 Last : out Positive)
102 Paren : Boolean;
103 Pos : Integer;
105 begin
106 String_Skip (From, Pos);
108 if From (Pos) = '(' then
109 Pos := Pos + 1;
110 Paren := True;
111 else
112 Paren := False;
113 end if;
115 Aux.Gets (From (Pos .. From'Last), ItemR, Pos);
117 String_Skip (From (Pos + 1 .. From'Last), Pos);
119 if From (Pos) = ',' then
120 Pos := Pos + 1;
121 end if;
123 Aux.Gets (From (Pos .. From'Last), ItemI, Pos);
125 if Paren then
126 String_Skip (From (Pos + 1 .. From'Last), Pos);
128 if From (Pos) /= ')' then
129 raise Data_Error;
130 end if;
131 end if;
133 Last := Pos;
134 end Gets;
136 ---------
137 -- Put --
138 ---------
140 procedure Put
141 (File : File_Type;
142 ItemR : Long_Long_Float;
143 ItemI : Long_Long_Float;
144 Fore : Field;
145 Aft : Field;
146 Exp : Field)
148 begin
149 Put (File, '(');
150 Aux.Put (File, ItemR, Fore, Aft, Exp);
151 Put (File, ',');
152 Aux.Put (File, ItemI, Fore, Aft, Exp);
153 Put (File, ')');
154 end Put;
156 ----------
157 -- Puts --
158 ----------
160 procedure Puts
161 (To : out String;
162 ItemR : Long_Long_Float;
163 ItemI : Long_Long_Float;
164 Aft : Field;
165 Exp : Field)
167 I_String : String (1 .. 3 * Field'Last);
168 R_String : String (1 .. 3 * Field'Last);
170 Iptr : Natural;
171 Rptr : Natural;
173 begin
174 -- Both parts are initially converted with a Fore of 0
176 Rptr := 0;
177 Set_Image_Real (ItemR, R_String, Rptr, 0, Aft, Exp);
178 Iptr := 0;
179 Set_Image_Real (ItemI, I_String, Iptr, 0, Aft, Exp);
181 -- Check room for both parts plus parens plus comma (RM G.1.3(34))
183 if Rptr + Iptr + 3 > To'Length then
184 raise Layout_Error;
185 end if;
187 -- If there is room, layout result according to (RM G.1.3(31-33))
189 To (To'First) := '(';
190 To (To'First + 1 .. To'First + Rptr) := R_String (1 .. Rptr);
191 To (To'First + Rptr + 1) := ',';
193 To (To'Last) := ')';
194 To (To'Last - Iptr .. To'Last - 1) := I_String (1 .. Iptr);
196 for J in To'First + Rptr + 2 .. To'Last - Iptr - 1 loop
197 To (J) := ' ';
198 end loop;
200 end Puts;
202 end Ada.Text_IO.Complex_Aux;