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--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2010, 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------------------------------------------------------------------------------
31
32--  This package contains the implementations of the stream attributes for
33--  elementary types. These are the subprograms that are directly accessed
34--  by occurrences of the stream attributes where the type is elementary.
35
36--  We only provide the subprograms for the standard base types. For user
37--  defined types, the subprogram for the corresponding root type is called
38--  with an appropriate conversion.
39
40with System;
41with System.Unsigned_Types;
42with Ada.Streams;
43
44package System.Stream_Attributes is
45   pragma Preelaborate;
46
47   pragma Suppress (Accessibility_Check, Stream_Attributes);
48   --  No need to check accessibility on arguments of subprograms
49
50   package UST renames System.Unsigned_Types;
51
52   subtype RST is Ada.Streams.Root_Stream_Type'Class;
53
54   subtype SEC is Ada.Streams.Stream_Element_Count;
55
56   --  Enumeration types are usually transferred using the routine for the
57   --  corresponding integer. The exception is that special routines are
58   --  provided for Boolean and the character types, in case the protocol
59   --  in use provides specially for these types.
60
61   --  Access types use either a thin pointer (single address) or fat pointer
62   --  (double address) form. The following types are used to hold access
63   --  values using unchecked conversions.
64
65   type Thin_Pointer is record
66      P1 : System.Address;
67   end record;
68
69   type Fat_Pointer is record
70      P1 : System.Address;
71      P2 : System.Address;
72   end record;
73
74   ------------------------------------
75   -- Treatment of enumeration types --
76   ------------------------------------
77
78   --  In this interface, there are no specific routines for general input
79   --  or output of enumeration types. Generally, enumeration types whose
80   --  representation is unsigned (no negative representation values) are
81   --  treated as unsigned integers, and enumeration types that do have
82   --  negative representation values are treated as signed integers.
83
84   --  An exception is that there are specialized routines for Boolean,
85   --  Character, and Wide_Character types, but these specialized routines
86   --  are used only if the type in question has a standard representation.
87   --  For the case of a non-standard representation (one where the size of
88   --  the first subtype is specified, or where an enumeration representation
89   --  clause is given, these three types are treated like any other cases
90   --  of enumeration types, as described above.
91   --  for
92
93   ---------------------
94   -- Input Functions --
95   ---------------------
96
97   --  Functions for S'Input attribute. These functions are also used for
98   --  S'Read, with the obvious transformation, since the input operation
99   --  is the same for all elementary types (no bounds or discriminants
100   --  are involved).
101
102   function I_AD  (Stream : not null access RST) return Fat_Pointer;
103   function I_AS  (Stream : not null access RST) return Thin_Pointer;
104   function I_B   (Stream : not null access RST) return Boolean;
105   function I_C   (Stream : not null access RST) return Character;
106   function I_F   (Stream : not null access RST) return Float;
107   function I_I   (Stream : not null access RST) return Integer;
108   function I_LF  (Stream : not null access RST) return Long_Float;
109   function I_LI  (Stream : not null access RST) return Long_Integer;
110   function I_LLF (Stream : not null access RST) return Long_Long_Float;
111   function I_LLI (Stream : not null access RST) return Long_Long_Integer;
112   function I_LLU (Stream : not null access RST) return UST.Long_Long_Unsigned;
113   function I_LU  (Stream : not null access RST) return UST.Long_Unsigned;
114   function I_SF  (Stream : not null access RST) return Short_Float;
115   function I_SI  (Stream : not null access RST) return Short_Integer;
116   function I_SSI (Stream : not null access RST) return Short_Short_Integer;
117   function I_SSU (Stream : not null access RST)
118     return UST.Short_Short_Unsigned;
119   function I_SU  (Stream : not null access RST) return UST.Short_Unsigned;
120   function I_U   (Stream : not null access RST) return UST.Unsigned;
121   function I_WC  (Stream : not null access RST) return Wide_Character;
122   function I_WWC (Stream : not null access RST) return Wide_Wide_Character;
123
124   -----------------------
125   -- Output Procedures --
126   -----------------------
127
128   --  Procedures for S'Write attribute. These procedures are also used
129   --  for 'Output, since for elementary types there is no difference
130   --  between 'Write and 'Output because there are no discriminants
131   --  or bounds to be written.
132
133   procedure W_AD  (Stream : not null access RST; Item : Fat_Pointer);
134   procedure W_AS  (Stream : not null access RST; Item : Thin_Pointer);
135   procedure W_B   (Stream : not null access RST; Item : Boolean);
136   procedure W_C   (Stream : not null access RST; Item : Character);
137   procedure W_F   (Stream : not null access RST; Item : Float);
138   procedure W_I   (Stream : not null access RST; Item : Integer);
139   procedure W_LF  (Stream : not null access RST; Item : Long_Float);
140   procedure W_LI  (Stream : not null access RST; Item : Long_Integer);
141   procedure W_LLF (Stream : not null access RST; Item : Long_Long_Float);
142   procedure W_LLI (Stream : not null access RST; Item : Long_Long_Integer);
143   procedure W_LLU (Stream : not null access RST;
144                    Item   : UST.Long_Long_Unsigned);
145   procedure W_LU  (Stream : not null access RST; Item : UST.Long_Unsigned);
146   procedure W_SF  (Stream : not null access RST; Item : Short_Float);
147   procedure W_SI  (Stream : not null access RST; Item : Short_Integer);
148   procedure W_SSI (Stream : not null access RST;
149                    Item   : Short_Short_Integer);
150   procedure W_SSU (Stream : not null access RST;
151                    Item   : UST.Short_Short_Unsigned);
152   procedure W_SU  (Stream : not null access RST;
153                    Item   : UST.Short_Unsigned);
154   procedure W_U   (Stream : not null access RST; Item : UST.Unsigned);
155   procedure W_WC  (Stream : not null access RST; Item : Wide_Character);
156   procedure W_WWC (Stream : not null access RST; Item : Wide_Wide_Character);
157
158   function Block_IO_OK return Boolean;
159   --  Package System.Stream_Attributes has several bodies - the default one
160   --  distributed with GNAT, and s-stratt-xdr.adb, which is based on the XDR
161   --  standard. Both bodies share the same spec. The role of this function is
162   --  to indicate whether the current version of System.Stream_Attributes
163   --  supports block IO.
164
165private
166   pragma Inline (I_AD);
167   pragma Inline (I_AS);
168   pragma Inline (I_B);
169   pragma Inline (I_C);
170   pragma Inline (I_F);
171   pragma Inline (I_I);
172   pragma Inline (I_LF);
173   pragma Inline (I_LI);
174   pragma Inline (I_LLF);
175   pragma Inline (I_LLI);
176   pragma Inline (I_LLU);
177   pragma Inline (I_LU);
178   pragma Inline (I_SF);
179   pragma Inline (I_SI);
180   pragma Inline (I_SSI);
181   pragma Inline (I_SSU);
182   pragma Inline (I_SU);
183   pragma Inline (I_U);
184   pragma Inline (I_WC);
185   pragma Inline (I_WWC);
186
187   pragma Inline (W_AD);
188   pragma Inline (W_AS);
189   pragma Inline (W_B);
190   pragma Inline (W_C);
191   pragma Inline (W_F);
192   pragma Inline (W_I);
193   pragma Inline (W_LF);
194   pragma Inline (W_LI);
195   pragma Inline (W_LLF);
196   pragma Inline (W_LLI);
197   pragma Inline (W_LLU);
198   pragma Inline (W_LU);
199   pragma Inline (W_SF);
200   pragma Inline (W_SI);
201   pragma Inline (W_SSI);
202   pragma Inline (W_SSU);
203   pragma Inline (W_SU);
204   pragma Inline (W_U);
205   pragma Inline (W_WC);
206   pragma Inline (W_WWC);
207
208   pragma Inline (Block_IO_OK);
209
210end System.Stream_Attributes;
211