OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [s-stratt.adb] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
------------------------------------------------------------------------------
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-2005, 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
------------------------------------------------------------------------------
33
 
34
with Ada.IO_Exceptions;
35
with Ada.Streams; use Ada.Streams;
36
with Unchecked_Conversion;
37
 
38
package body System.Stream_Attributes is
39
 
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).
44
 
45
   SU : constant := System.Storage_Unit;
46
 
47
   subtype SEA is Ada.Streams.Stream_Element_Array;
48
   subtype SEO is Ada.Streams.Stream_Element_Offset;
49
 
50
   generic function UC renames Unchecked_Conversion;
51
 
52
   --  Subtypes used to define Stream_Element_Array values that map
53
   --  into the elementary types, using unchecked conversion.
54
 
55
   Thin_Pointer_Size : constant := System.Address'Size;
56
   Fat_Pointer_Size  : constant := System.Address'Size * 2;
57
 
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);
77
 
78
   --  Unchecked conversions from the elementary type to the stream type
79
 
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);
97
 
98
   --  Unchecked conversions from the stream type to elementary type
99
 
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);
117
 
118
   ----------
119
   -- I_AD --
120
   ----------
121
 
122
   function I_AD (Stream : not null access RST) return Fat_Pointer is
123
      T : S_AD;
124
      L : SEO;
125
 
126
   begin
127
      Ada.Streams.Read (Stream.all, T, L);
128
 
129
      if L < T'Last then
130
         raise Err;
131
      else
132
         return To_AD (T);
133
      end if;
134
   end I_AD;
135
 
136
   ----------
137
   -- I_AS --
138
   ----------
139
 
140
   function I_AS (Stream : not null access RST) return Thin_Pointer is
141
      T : S_AS;
142
      L : SEO;
143
 
144
   begin
145
      Ada.Streams.Read (Stream.all, T, L);
146
 
147
      if L < T'Last then
148
         raise Err;
149
      else
150
         return To_AS (T);
151
      end if;
152
   end I_AS;
153
 
154
   ---------
155
   -- I_B --
156
   ---------
157
 
158
   function I_B (Stream : not null access RST) return Boolean is
159
      T : S_B;
160
      L : SEO;
161
 
162
   begin
163
      Ada.Streams.Read (Stream.all, T, L);
164
 
165
      if L < T'Last then
166
         raise Err;
167
      else
168
         return Boolean'Val (T (1));
169
      end if;
170
   end I_B;
171
 
172
   ---------
173
   -- I_C --
174
   ---------
175
 
176
   function I_C (Stream : not null access RST) return Character is
177
      T : S_C;
178
      L : SEO;
179
 
180
   begin
181
      Ada.Streams.Read (Stream.all, T, L);
182
 
183
      if L < T'Last then
184
         raise Err;
185
      else
186
         return Character'Val (T (1));
187
      end if;
188
   end I_C;
189
 
190
   ---------
191
   -- I_F --
192
   ---------
193
 
194
   function I_F (Stream : not null access RST) return Float is
195
      T : S_F;
196
      L : SEO;
197
 
198
   begin
199
      Ada.Streams.Read (Stream.all, T, L);
200
 
201
      if L < T'Last then
202
         raise Err;
203
      else
204
         return To_F (T);
205
      end if;
206
   end I_F;
207
 
208
   ---------
209
   -- I_I --
210
   ---------
211
 
212
   function I_I (Stream : not null access RST) return Integer is
213
      T : S_I;
214
      L : SEO;
215
 
216
   begin
217
      Ada.Streams.Read (Stream.all, T, L);
218
 
219
      if L < T'Last then
220
         raise Err;
221
      else
222
         return To_I (T);
223
      end if;
224
   end I_I;
225
 
226
   ----------
227
   -- I_LF --
228
   ----------
229
 
230
   function I_LF (Stream : not null access RST) return Long_Float is
231
      T : S_LF;
232
      L : SEO;
233
 
234
   begin
235
      Ada.Streams.Read (Stream.all, T, L);
236
 
237
      if L < T'Last then
238
         raise Err;
239
      else
240
         return To_LF (T);
241
      end if;
242
   end I_LF;
243
 
244
   ----------
245
   -- I_LI --
246
   ----------
247
 
248
   function I_LI (Stream : not null access RST) return Long_Integer is
249
      T : S_LI;
250
      L : SEO;
251
 
252
   begin
253
      Ada.Streams.Read (Stream.all, T, L);
254
 
255
      if L < T'Last then
256
         raise Err;
257
      else
258
         return To_LI (T);
259
      end if;
260
   end I_LI;
261
 
262
   -----------
263
   -- I_LLF --
264
   -----------
265
 
266
   function I_LLF (Stream : not null access RST) return Long_Long_Float is
267
      T : S_LLF;
268
      L : SEO;
269
 
270
   begin
271
      Ada.Streams.Read (Stream.all, T, L);
272
 
273
      if L < T'Last then
274
         raise Err;
275
      else
276
         return To_LLF (T);
277
      end if;
278
   end I_LLF;
279
 
280
   -----------
281
   -- I_LLI --
282
   -----------
283
 
284
   function I_LLI (Stream : not null access RST) return Long_Long_Integer is
285
      T : S_LLI;
286
      L : SEO;
287
 
288
   begin
289
      Ada.Streams.Read (Stream.all, T, L);
290
 
291
      if L < T'Last then
292
         raise Err;
293
      else
294
         return To_LLI (T);
295
      end if;
296
   end I_LLI;
297
 
298
   -----------
299
   -- I_LLU --
300
   -----------
301
 
302
   function I_LLU
303
     (Stream : not null access RST) return UST.Long_Long_Unsigned
304
   is
305
      T : S_LLU;
306
      L : SEO;
307
 
308
   begin
309
      Ada.Streams.Read (Stream.all, T, L);
310
 
311
      if L < T'Last then
312
         raise Err;
313
      else
314
         return To_LLU (T);
315
      end if;
316
   end I_LLU;
317
 
318
   ----------
319
   -- I_LU --
320
   ----------
321
 
322
   function I_LU (Stream : not null access RST) return UST.Long_Unsigned is
323
      T : S_LU;
324
      L : SEO;
325
 
326
   begin
327
      Ada.Streams.Read (Stream.all, T, L);
328
 
329
      if L < T'Last then
330
         raise Err;
331
      else
332
         return To_LU (T);
333
      end if;
334
   end I_LU;
335
 
336
   ----------
337
   -- I_SF --
338
   ----------
339
 
340
   function I_SF (Stream : not null access RST) return Short_Float is
341
      T : S_SF;
342
      L : SEO;
343
 
344
   begin
345
      Ada.Streams.Read (Stream.all, T, L);
346
 
347
      if L < T'Last then
348
         raise Err;
349
      else
350
         return To_SF (T);
351
      end if;
352
   end I_SF;
353
 
354
   ----------
355
   -- I_SI --
356
   ----------
357
 
358
   function I_SI (Stream : not null access RST) return Short_Integer is
359
      T : S_SI;
360
      L : SEO;
361
 
362
   begin
363
      Ada.Streams.Read (Stream.all, T, L);
364
 
365
      if L < T'Last then
366
         raise Err;
367
      else
368
         return To_SI (T);
369
      end if;
370
   end I_SI;
371
 
372
   -----------
373
   -- I_SSI --
374
   -----------
375
 
376
   function I_SSI (Stream : not null access RST) return Short_Short_Integer is
377
      T : S_SSI;
378
      L : SEO;
379
 
380
   begin
381
      Ada.Streams.Read (Stream.all, T, L);
382
 
383
      if L < T'Last then
384
         raise Err;
385
      else
386
         return To_SSI (T);
387
      end if;
388
   end I_SSI;
389
 
390
   -----------
391
   -- I_SSU --
392
   -----------
393
 
394
   function I_SSU
395
     (Stream : not null access RST) return UST.Short_Short_Unsigned
396
   is
397
      T : S_SSU;
398
      L : SEO;
399
 
400
   begin
401
      Ada.Streams.Read (Stream.all, T, L);
402
 
403
      if L < T'Last then
404
         raise Err;
405
      else
406
         return To_SSU (T);
407
      end if;
408
   end I_SSU;
409
 
410
   ----------
411
   -- I_SU --
412
   ----------
413
 
414
   function I_SU (Stream : not null access RST) return UST.Short_Unsigned is
415
      T : S_SU;
416
      L : SEO;
417
 
418
   begin
419
      Ada.Streams.Read (Stream.all, T, L);
420
 
421
      if L < T'Last then
422
         raise Err;
423
      else
424
         return To_SU (T);
425
      end if;
426
   end I_SU;
427
 
428
   ---------
429
   -- I_U --
430
   ---------
431
 
432
   function I_U (Stream : not null access RST) return UST.Unsigned is
433
      T : S_U;
434
      L : SEO;
435
 
436
   begin
437
      Ada.Streams.Read (Stream.all, T, L);
438
 
439
      if L < T'Last then
440
         raise Err;
441
      else
442
         return To_U (T);
443
      end if;
444
   end I_U;
445
 
446
   ----------
447
   -- I_WC --
448
   ----------
449
 
450
   function I_WC (Stream : not null access RST) return Wide_Character is
451
      T : S_WC;
452
      L : SEO;
453
 
454
   begin
455
      Ada.Streams.Read (Stream.all, T, L);
456
 
457
      if L < T'Last then
458
         raise Err;
459
      else
460
         return To_WC (T);
461
      end if;
462
   end I_WC;
463
 
464
   ----------
465
   -- W_AD --
466
   ----------
467
 
468
   procedure W_AD (Stream : not null access RST; Item : in Fat_Pointer) is
469
      T : constant S_AD := From_AD (Item);
470
 
471
   begin
472
      Ada.Streams.Write (Stream.all, T);
473
   end W_AD;
474
 
475
   ----------
476
   -- W_AS --
477
   ----------
478
 
479
   procedure W_AS (Stream : not null access RST; Item : in Thin_Pointer) is
480
      T : constant S_AS := From_AS (Item);
481
 
482
   begin
483
      Ada.Streams.Write (Stream.all, T);
484
   end W_AS;
485
 
486
   ---------
487
   -- W_B --
488
   ---------
489
 
490
   procedure W_B (Stream : not null access RST; Item : in Boolean) is
491
      T : S_B;
492
 
493
   begin
494
      T (1) := Boolean'Pos (Item);
495
      Ada.Streams.Write (Stream.all, T);
496
   end W_B;
497
 
498
   ---------
499
   -- W_C --
500
   ---------
501
 
502
   procedure W_C (Stream : not null access RST; Item : in Character) is
503
      T : S_C;
504
 
505
   begin
506
      T (1) := Character'Pos (Item);
507
      Ada.Streams.Write (Stream.all, T);
508
   end W_C;
509
 
510
   ---------
511
   -- W_F --
512
   ---------
513
 
514
   procedure W_F (Stream : not null access RST; Item : in Float) is
515
      T : constant S_F := From_F (Item);
516
 
517
   begin
518
      Ada.Streams.Write (Stream.all, T);
519
   end W_F;
520
 
521
   ---------
522
   -- W_I --
523
   ---------
524
 
525
   procedure W_I (Stream : not null access RST; Item : in Integer) is
526
      T : constant S_I := From_I (Item);
527
 
528
   begin
529
      Ada.Streams.Write (Stream.all, T);
530
   end W_I;
531
 
532
   ----------
533
   -- W_LF --
534
   ----------
535
 
536
   procedure W_LF (Stream : not null access RST; Item : in Long_Float) is
537
      T : constant S_LF := From_LF (Item);
538
 
539
   begin
540
      Ada.Streams.Write (Stream.all, T);
541
   end W_LF;
542
 
543
   ----------
544
   -- W_LI --
545
   ----------
546
 
547
   procedure W_LI (Stream : not null access RST; Item : in Long_Integer) is
548
      T : constant S_LI := From_LI (Item);
549
 
550
   begin
551
      Ada.Streams.Write (Stream.all, T);
552
   end W_LI;
553
 
554
   -----------
555
   -- W_LLF --
556
   -----------
557
 
558
   procedure W_LLF (Stream : not null access RST; Item : in Long_Long_Float) is
559
      T : constant S_LLF := From_LLF (Item);
560
 
561
   begin
562
      Ada.Streams.Write (Stream.all, T);
563
   end W_LLF;
564
 
565
   -----------
566
   -- W_LLI --
567
   -----------
568
 
569
   procedure W_LLI
570
     (Stream : not null access RST; Item : in Long_Long_Integer)
571
   is
572
      T : constant S_LLI := From_LLI (Item);
573
 
574
   begin
575
      Ada.Streams.Write (Stream.all, T);
576
   end W_LLI;
577
 
578
   -----------
579
   -- W_LLU --
580
   -----------
581
 
582
   procedure W_LLU
583
     (Stream : not null access RST; Item : in UST.Long_Long_Unsigned)
584
   is
585
      T : constant S_LLU := From_LLU (Item);
586
 
587
   begin
588
      Ada.Streams.Write (Stream.all, T);
589
   end W_LLU;
590
 
591
   ----------
592
   -- W_LU --
593
   ----------
594
 
595
   procedure W_LU
596
     (Stream : not null access RST; Item : in UST.Long_Unsigned)
597
   is
598
      T : constant S_LU := From_LU (Item);
599
 
600
   begin
601
      Ada.Streams.Write (Stream.all, T);
602
   end W_LU;
603
 
604
   ----------
605
   -- W_SF --
606
   ----------
607
 
608
   procedure W_SF (Stream : not null access RST; Item : in Short_Float) is
609
      T : constant S_SF := From_SF (Item);
610
 
611
   begin
612
      Ada.Streams.Write (Stream.all, T);
613
   end W_SF;
614
 
615
   ----------
616
   -- W_SI --
617
   ----------
618
 
619
   procedure W_SI (Stream : not null access RST; Item : in Short_Integer) is
620
      T : constant S_SI := From_SI (Item);
621
 
622
   begin
623
      Ada.Streams.Write (Stream.all, T);
624
   end W_SI;
625
 
626
   -----------
627
   -- W_SSI --
628
   -----------
629
 
630
   procedure W_SSI
631
     (Stream : not null access RST; Item : in Short_Short_Integer)
632
   is
633
      T : constant S_SSI := From_SSI (Item);
634
 
635
   begin
636
      Ada.Streams.Write (Stream.all, T);
637
   end W_SSI;
638
 
639
   -----------
640
   -- W_SSU --
641
   -----------
642
 
643
   procedure W_SSU
644
     (Stream : not null access RST; Item : in UST.Short_Short_Unsigned)
645
   is
646
      T : constant S_SSU := From_SSU (Item);
647
 
648
   begin
649
      Ada.Streams.Write (Stream.all, T);
650
   end W_SSU;
651
 
652
   ----------
653
   -- W_SU --
654
   ----------
655
 
656
   procedure W_SU
657
     (Stream : not null access RST; Item : in UST.Short_Unsigned)
658
   is
659
      T : constant S_SU := From_SU (Item);
660
 
661
   begin
662
      Ada.Streams.Write (Stream.all, T);
663
   end W_SU;
664
 
665
   ---------
666
   -- W_U --
667
   ---------
668
 
669
   procedure W_U (Stream : not null access RST; Item : in UST.Unsigned) is
670
      T : constant S_U := From_U (Item);
671
 
672
   begin
673
      Ada.Streams.Write (Stream.all, T);
674
   end W_U;
675
 
676
   ----------
677
   -- W_WC --
678
   ----------
679
 
680
   procedure W_WC (Stream : not null access RST; Item : in Wide_Character) is
681
      T : constant S_WC := From_WC (Item);
682
 
683
   begin
684
      Ada.Streams.Write (Stream.all, T);
685
   end W_WC;
686
 
687
end System.Stream_Attributes;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.