2006-06-30 Andrew Pinski <pinskia@gmail.com>
[official-gcc.git] / gcc / ada / s-stratt.adb
blob9601979ef9c0191d6c0715d853604a869e099e06
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . S T R E A M _ A T T R I B U T E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2006, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with Ada.IO_Exceptions;
35 with Ada.Streams; use Ada.Streams;
36 with Unchecked_Conversion;
38 package body System.Stream_Attributes is
40 Err : exception renames Ada.IO_Exceptions.End_Error;
41 -- Exception raised if insufficient data read (note that the RM implies
42 -- that Data_Error might be the appropriate choice, but AI95-00132
43 -- decides with a binding interpretation that End_Error is preferred).
45 SU : constant := System.Storage_Unit;
47 subtype SEA is Ada.Streams.Stream_Element_Array;
48 subtype SEO is Ada.Streams.Stream_Element_Offset;
50 generic function UC renames Unchecked_Conversion;
52 -- Subtypes used to define Stream_Element_Array values that map
53 -- into the elementary types, using unchecked conversion.
55 Thin_Pointer_Size : constant := System.Address'Size;
56 Fat_Pointer_Size : constant := System.Address'Size * 2;
58 subtype S_AD is SEA (1 .. (Fat_Pointer_Size + SU - 1) / SU);
59 subtype S_AS is SEA (1 .. (Thin_Pointer_Size + SU - 1) / SU);
60 subtype S_B is SEA (1 .. (Boolean'Size + SU - 1) / SU);
61 subtype S_C is SEA (1 .. (Character'Size + SU - 1) / SU);
62 subtype S_F is SEA (1 .. (Float'Size + SU - 1) / SU);
63 subtype S_I is SEA (1 .. (Integer'Size + SU - 1) / SU);
64 subtype S_LF is SEA (1 .. (Long_Float'Size + SU - 1) / SU);
65 subtype S_LI is SEA (1 .. (Long_Integer'Size + SU - 1) / SU);
66 subtype S_LLF is SEA (1 .. (Long_Long_Float'Size + SU - 1) / SU);
67 subtype S_LLI is SEA (1 .. (Long_Long_Integer'Size + SU - 1) / SU);
68 subtype S_LLU is SEA (1 .. (UST.Long_Long_Unsigned'Size + SU - 1) / SU);
69 subtype S_LU is SEA (1 .. (UST.Long_Unsigned'Size + SU - 1) / SU);
70 subtype S_SF is SEA (1 .. (Short_Float'Size + SU - 1) / SU);
71 subtype S_SI is SEA (1 .. (Short_Integer'Size + SU - 1) / SU);
72 subtype S_SSI is SEA (1 .. (Short_Short_Integer'Size + SU - 1) / SU);
73 subtype S_SSU is SEA (1 .. (UST.Short_Short_Unsigned'Size + SU - 1) / SU);
74 subtype S_SU is SEA (1 .. (UST.Short_Unsigned'Size + SU - 1) / SU);
75 subtype S_U is SEA (1 .. (UST.Unsigned'Size + SU - 1) / SU);
76 subtype S_WC is SEA (1 .. (Wide_Character'Size + SU - 1) / SU);
78 -- Unchecked conversions from the elementary type to the stream type
80 function From_AD is new UC (Fat_Pointer, S_AD);
81 function From_AS is new UC (Thin_Pointer, S_AS);
82 function From_F is new UC (Float, S_F);
83 function From_I is new UC (Integer, S_I);
84 function From_LF is new UC (Long_Float, S_LF);
85 function From_LI is new UC (Long_Integer, S_LI);
86 function From_LLF is new UC (Long_Long_Float, S_LLF);
87 function From_LLI is new UC (Long_Long_Integer, S_LLI);
88 function From_LLU is new UC (UST.Long_Long_Unsigned, S_LLU);
89 function From_LU is new UC (UST.Long_Unsigned, S_LU);
90 function From_SF is new UC (Short_Float, S_SF);
91 function From_SI is new UC (Short_Integer, S_SI);
92 function From_SSI is new UC (Short_Short_Integer, S_SSI);
93 function From_SSU is new UC (UST.Short_Short_Unsigned, S_SSU);
94 function From_SU is new UC (UST.Short_Unsigned, S_SU);
95 function From_U is new UC (UST.Unsigned, S_U);
96 function From_WC is new UC (Wide_Character, S_WC);
98 -- Unchecked conversions from the stream type to elementary type
100 function To_AD is new UC (S_AD, Fat_Pointer);
101 function To_AS is new UC (S_AS, Thin_Pointer);
102 function To_F is new UC (S_F, Float);
103 function To_I is new UC (S_I, Integer);
104 function To_LF is new UC (S_LF, Long_Float);
105 function To_LI is new UC (S_LI, Long_Integer);
106 function To_LLF is new UC (S_LLF, Long_Long_Float);
107 function To_LLI is new UC (S_LLI, Long_Long_Integer);
108 function To_LLU is new UC (S_LLU, UST.Long_Long_Unsigned);
109 function To_LU is new UC (S_LU, UST.Long_Unsigned);
110 function To_SF is new UC (S_SF, Short_Float);
111 function To_SI is new UC (S_SI, Short_Integer);
112 function To_SSI is new UC (S_SSI, Short_Short_Integer);
113 function To_SSU is new UC (S_SSU, UST.Short_Short_Unsigned);
114 function To_SU is new UC (S_SU, UST.Short_Unsigned);
115 function To_U is new UC (S_U, UST.Unsigned);
116 function To_WC is new UC (S_WC, Wide_Character);
118 ----------
119 -- I_AD --
120 ----------
122 function I_AD (Stream : not null access RST) return Fat_Pointer is
123 T : S_AD;
124 L : SEO;
126 begin
127 Ada.Streams.Read (Stream.all, T, L);
129 if L < T'Last then
130 raise Err;
131 else
132 return To_AD (T);
133 end if;
134 end I_AD;
136 ----------
137 -- I_AS --
138 ----------
140 function I_AS (Stream : not null access RST) return Thin_Pointer is
141 T : S_AS;
142 L : SEO;
144 begin
145 Ada.Streams.Read (Stream.all, T, L);
147 if L < T'Last then
148 raise Err;
149 else
150 return To_AS (T);
151 end if;
152 end I_AS;
154 ---------
155 -- I_B --
156 ---------
158 function I_B (Stream : not null access RST) return Boolean is
159 T : S_B;
160 L : SEO;
162 begin
163 Ada.Streams.Read (Stream.all, T, L);
165 if L < T'Last then
166 raise Err;
167 else
168 return Boolean'Val (T (1));
169 end if;
170 end I_B;
172 ---------
173 -- I_C --
174 ---------
176 function I_C (Stream : not null access RST) return Character is
177 T : S_C;
178 L : SEO;
180 begin
181 Ada.Streams.Read (Stream.all, T, L);
183 if L < T'Last then
184 raise Err;
185 else
186 return Character'Val (T (1));
187 end if;
188 end I_C;
190 ---------
191 -- I_F --
192 ---------
194 function I_F (Stream : not null access RST) return Float is
195 T : S_F;
196 L : SEO;
198 begin
199 Ada.Streams.Read (Stream.all, T, L);
201 if L < T'Last then
202 raise Err;
203 else
204 return To_F (T);
205 end if;
206 end I_F;
208 ---------
209 -- I_I --
210 ---------
212 function I_I (Stream : not null access RST) return Integer is
213 T : S_I;
214 L : SEO;
216 begin
217 Ada.Streams.Read (Stream.all, T, L);
219 if L < T'Last then
220 raise Err;
221 else
222 return To_I (T);
223 end if;
224 end I_I;
226 ----------
227 -- I_LF --
228 ----------
230 function I_LF (Stream : not null access RST) return Long_Float is
231 T : S_LF;
232 L : SEO;
234 begin
235 Ada.Streams.Read (Stream.all, T, L);
237 if L < T'Last then
238 raise Err;
239 else
240 return To_LF (T);
241 end if;
242 end I_LF;
244 ----------
245 -- I_LI --
246 ----------
248 function I_LI (Stream : not null access RST) return Long_Integer is
249 T : S_LI;
250 L : SEO;
252 begin
253 Ada.Streams.Read (Stream.all, T, L);
255 if L < T'Last then
256 raise Err;
257 else
258 return To_LI (T);
259 end if;
260 end I_LI;
262 -----------
263 -- I_LLF --
264 -----------
266 function I_LLF (Stream : not null access RST) return Long_Long_Float is
267 T : S_LLF;
268 L : SEO;
270 begin
271 Ada.Streams.Read (Stream.all, T, L);
273 if L < T'Last then
274 raise Err;
275 else
276 return To_LLF (T);
277 end if;
278 end I_LLF;
280 -----------
281 -- I_LLI --
282 -----------
284 function I_LLI (Stream : not null access RST) return Long_Long_Integer is
285 T : S_LLI;
286 L : SEO;
288 begin
289 Ada.Streams.Read (Stream.all, T, L);
291 if L < T'Last then
292 raise Err;
293 else
294 return To_LLI (T);
295 end if;
296 end I_LLI;
298 -----------
299 -- I_LLU --
300 -----------
302 function I_LLU
303 (Stream : not null access RST) return UST.Long_Long_Unsigned
305 T : S_LLU;
306 L : SEO;
308 begin
309 Ada.Streams.Read (Stream.all, T, L);
311 if L < T'Last then
312 raise Err;
313 else
314 return To_LLU (T);
315 end if;
316 end I_LLU;
318 ----------
319 -- I_LU --
320 ----------
322 function I_LU (Stream : not null access RST) return UST.Long_Unsigned is
323 T : S_LU;
324 L : SEO;
326 begin
327 Ada.Streams.Read (Stream.all, T, L);
329 if L < T'Last then
330 raise Err;
331 else
332 return To_LU (T);
333 end if;
334 end I_LU;
336 ----------
337 -- I_SF --
338 ----------
340 function I_SF (Stream : not null access RST) return Short_Float is
341 T : S_SF;
342 L : SEO;
344 begin
345 Ada.Streams.Read (Stream.all, T, L);
347 if L < T'Last then
348 raise Err;
349 else
350 return To_SF (T);
351 end if;
352 end I_SF;
354 ----------
355 -- I_SI --
356 ----------
358 function I_SI (Stream : not null access RST) return Short_Integer is
359 T : S_SI;
360 L : SEO;
362 begin
363 Ada.Streams.Read (Stream.all, T, L);
365 if L < T'Last then
366 raise Err;
367 else
368 return To_SI (T);
369 end if;
370 end I_SI;
372 -----------
373 -- I_SSI --
374 -----------
376 function I_SSI (Stream : not null access RST) return Short_Short_Integer is
377 T : S_SSI;
378 L : SEO;
380 begin
381 Ada.Streams.Read (Stream.all, T, L);
383 if L < T'Last then
384 raise Err;
385 else
386 return To_SSI (T);
387 end if;
388 end I_SSI;
390 -----------
391 -- I_SSU --
392 -----------
394 function I_SSU
395 (Stream : not null access RST) return UST.Short_Short_Unsigned
397 T : S_SSU;
398 L : SEO;
400 begin
401 Ada.Streams.Read (Stream.all, T, L);
403 if L < T'Last then
404 raise Err;
405 else
406 return To_SSU (T);
407 end if;
408 end I_SSU;
410 ----------
411 -- I_SU --
412 ----------
414 function I_SU (Stream : not null access RST) return UST.Short_Unsigned is
415 T : S_SU;
416 L : SEO;
418 begin
419 Ada.Streams.Read (Stream.all, T, L);
421 if L < T'Last then
422 raise Err;
423 else
424 return To_SU (T);
425 end if;
426 end I_SU;
428 ---------
429 -- I_U --
430 ---------
432 function I_U (Stream : not null access RST) return UST.Unsigned is
433 T : S_U;
434 L : SEO;
436 begin
437 Ada.Streams.Read (Stream.all, T, L);
439 if L < T'Last then
440 raise Err;
441 else
442 return To_U (T);
443 end if;
444 end I_U;
446 ----------
447 -- I_WC --
448 ----------
450 function I_WC (Stream : not null access RST) return Wide_Character is
451 T : S_WC;
452 L : SEO;
454 begin
455 Ada.Streams.Read (Stream.all, T, L);
457 if L < T'Last then
458 raise Err;
459 else
460 return To_WC (T);
461 end if;
462 end I_WC;
464 ----------
465 -- W_AD --
466 ----------
468 procedure W_AD (Stream : not null access RST; Item : Fat_Pointer) is
469 T : constant S_AD := From_AD (Item);
470 begin
471 Ada.Streams.Write (Stream.all, T);
472 end W_AD;
474 ----------
475 -- W_AS --
476 ----------
478 procedure W_AS (Stream : not null access RST; Item : Thin_Pointer) is
479 T : constant S_AS := From_AS (Item);
480 begin
481 Ada.Streams.Write (Stream.all, T);
482 end W_AS;
484 ---------
485 -- W_B --
486 ---------
488 procedure W_B (Stream : not null access RST; Item : Boolean) is
489 T : S_B;
490 begin
491 T (1) := Boolean'Pos (Item);
492 Ada.Streams.Write (Stream.all, T);
493 end W_B;
495 ---------
496 -- W_C --
497 ---------
499 procedure W_C (Stream : not null access RST; Item : Character) is
500 T : S_C;
501 begin
502 T (1) := Character'Pos (Item);
503 Ada.Streams.Write (Stream.all, T);
504 end W_C;
506 ---------
507 -- W_F --
508 ---------
510 procedure W_F (Stream : not null access RST; Item : Float) is
511 T : constant S_F := From_F (Item);
512 begin
513 Ada.Streams.Write (Stream.all, T);
514 end W_F;
516 ---------
517 -- W_I --
518 ---------
520 procedure W_I (Stream : not null access RST; Item : Integer) is
521 T : constant S_I := From_I (Item);
522 begin
523 Ada.Streams.Write (Stream.all, T);
524 end W_I;
526 ----------
527 -- W_LF --
528 ----------
530 procedure W_LF (Stream : not null access RST; Item : Long_Float) is
531 T : constant S_LF := From_LF (Item);
532 begin
533 Ada.Streams.Write (Stream.all, T);
534 end W_LF;
536 ----------
537 -- W_LI --
538 ----------
540 procedure W_LI (Stream : not null access RST; Item : Long_Integer) is
541 T : constant S_LI := From_LI (Item);
542 begin
543 Ada.Streams.Write (Stream.all, T);
544 end W_LI;
546 -----------
547 -- W_LLF --
548 -----------
550 procedure W_LLF (Stream : not null access RST; Item : Long_Long_Float) is
551 T : constant S_LLF := From_LLF (Item);
552 begin
553 Ada.Streams.Write (Stream.all, T);
554 end W_LLF;
556 -----------
557 -- W_LLI --
558 -----------
560 procedure W_LLI
561 (Stream : not null access RST; Item : Long_Long_Integer)
563 T : constant S_LLI := From_LLI (Item);
564 begin
565 Ada.Streams.Write (Stream.all, T);
566 end W_LLI;
568 -----------
569 -- W_LLU --
570 -----------
572 procedure W_LLU
573 (Stream : not null access RST; Item : UST.Long_Long_Unsigned)
575 T : constant S_LLU := From_LLU (Item);
576 begin
577 Ada.Streams.Write (Stream.all, T);
578 end W_LLU;
580 ----------
581 -- W_LU --
582 ----------
584 procedure W_LU
585 (Stream : not null access RST; Item : UST.Long_Unsigned)
587 T : constant S_LU := From_LU (Item);
588 begin
589 Ada.Streams.Write (Stream.all, T);
590 end W_LU;
592 ----------
593 -- W_SF --
594 ----------
596 procedure W_SF (Stream : not null access RST; Item : Short_Float) is
597 T : constant S_SF := From_SF (Item);
598 begin
599 Ada.Streams.Write (Stream.all, T);
600 end W_SF;
602 ----------
603 -- W_SI --
604 ----------
606 procedure W_SI (Stream : not null access RST; Item : Short_Integer) is
607 T : constant S_SI := From_SI (Item);
608 begin
609 Ada.Streams.Write (Stream.all, T);
610 end W_SI;
612 -----------
613 -- W_SSI --
614 -----------
616 procedure W_SSI
617 (Stream : not null access RST; Item : Short_Short_Integer)
619 T : constant S_SSI := From_SSI (Item);
620 begin
621 Ada.Streams.Write (Stream.all, T);
622 end W_SSI;
624 -----------
625 -- W_SSU --
626 -----------
628 procedure W_SSU
629 (Stream : not null access RST; Item : UST.Short_Short_Unsigned)
631 T : constant S_SSU := From_SSU (Item);
632 begin
633 Ada.Streams.Write (Stream.all, T);
634 end W_SSU;
636 ----------
637 -- W_SU --
638 ----------
640 procedure W_SU
641 (Stream : not null access RST; Item : UST.Short_Unsigned)
643 T : constant S_SU := From_SU (Item);
644 begin
645 Ada.Streams.Write (Stream.all, T);
646 end W_SU;
648 ---------
649 -- W_U --
650 ---------
652 procedure W_U (Stream : not null access RST; Item : UST.Unsigned) is
653 T : constant S_U := From_U (Item);
654 begin
655 Ada.Streams.Write (Stream.all, T);
656 end W_U;
658 ----------
659 -- W_WC --
660 ----------
662 procedure W_WC (Stream : not null access RST; Item : Wide_Character) is
663 T : constant S_WC := From_WC (Item);
664 begin
665 Ada.Streams.Write (Stream.all, T);
666 end W_WC;
668 end System.Stream_Attributes;