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