annotate gcc/ada/libgnat/a-ststio.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . S T R E A M S . S T R E A M _ I O --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
33 -- --
kono
parents:
diff changeset
34 ------------------------------------------------------------------------------
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 with Ada.IO_Exceptions;
kono
parents:
diff changeset
37 with System.File_Control_Block;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 package Ada.Streams.Stream_IO is
kono
parents:
diff changeset
40 pragma Preelaborate;
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 type Stream_Access is access all Root_Stream_Type'Class;
kono
parents:
diff changeset
43
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
44 type File_Type is limited private with Default_Initial_Condition;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
45 pragma Preelaborable_Initialization (File_Type);
111
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 type File_Mode is (In_File, Out_File, Append_File);
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- The following representation clause allows the use of unchecked
kono
parents:
diff changeset
50 -- conversion for rapid translation between the File_Mode type
kono
parents:
diff changeset
51 -- used in this package and System.File_IO.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 for File_Mode use
kono
parents:
diff changeset
54 (In_File => 0, -- System.File_IO.File_Mode'Pos (In_File)
kono
parents:
diff changeset
55 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
kono
parents:
diff changeset
56 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 type Count is new Stream_Element_Offset
kono
parents:
diff changeset
59 range 0 .. Stream_Element_Offset'Last;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 subtype Positive_Count is Count range 1 .. Count'Last;
kono
parents:
diff changeset
62 -- Index into file, in stream elements
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 ---------------------
kono
parents:
diff changeset
65 -- File Management --
kono
parents:
diff changeset
66 ---------------------
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 procedure Create
kono
parents:
diff changeset
69 (File : in out File_Type;
kono
parents:
diff changeset
70 Mode : File_Mode := Out_File;
kono
parents:
diff changeset
71 Name : String := "";
kono
parents:
diff changeset
72 Form : String := "");
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 procedure Open
kono
parents:
diff changeset
75 (File : in out File_Type;
kono
parents:
diff changeset
76 Mode : File_Mode;
kono
parents:
diff changeset
77 Name : String;
kono
parents:
diff changeset
78 Form : String := "");
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 procedure Close (File : in out File_Type);
kono
parents:
diff changeset
81 procedure Delete (File : in out File_Type);
kono
parents:
diff changeset
82 procedure Reset (File : in out File_Type; Mode : File_Mode);
kono
parents:
diff changeset
83 procedure Reset (File : in out File_Type);
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 function Mode (File : File_Type) return File_Mode;
kono
parents:
diff changeset
86 function Name (File : File_Type) return String;
kono
parents:
diff changeset
87 function Form (File : File_Type) return String;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 function Is_Open (File : File_Type) return Boolean;
kono
parents:
diff changeset
90 function End_Of_File (File : File_Type) return Boolean;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 function Stream (File : File_Type) return Stream_Access;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 -----------------------------
kono
parents:
diff changeset
95 -- Input-Output Operations --
kono
parents:
diff changeset
96 -----------------------------
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 procedure Read
kono
parents:
diff changeset
99 (File : File_Type;
kono
parents:
diff changeset
100 Item : out Stream_Element_Array;
kono
parents:
diff changeset
101 Last : out Stream_Element_Offset;
kono
parents:
diff changeset
102 From : Positive_Count);
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 procedure Read
kono
parents:
diff changeset
105 (File : File_Type;
kono
parents:
diff changeset
106 Item : out Stream_Element_Array;
kono
parents:
diff changeset
107 Last : out Stream_Element_Offset);
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 procedure Write
kono
parents:
diff changeset
110 (File : File_Type;
kono
parents:
diff changeset
111 Item : Stream_Element_Array;
kono
parents:
diff changeset
112 To : Positive_Count);
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 procedure Write
kono
parents:
diff changeset
115 (File : File_Type;
kono
parents:
diff changeset
116 Item : Stream_Element_Array);
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 ----------------------------------------
kono
parents:
diff changeset
119 -- Operations on Position within File --
kono
parents:
diff changeset
120 ----------------------------------------
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 procedure Set_Index (File : File_Type; To : Positive_Count);
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 function Index (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
125 function Size (File : File_Type) return Count;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 procedure Set_Mode (File : in out File_Type; Mode : File_Mode);
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -- Note: The parameter file is IN OUT in the RM, but this is clearly
kono
parents:
diff changeset
130 -- an oversight, and was intended to be IN, see AI95-00057.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 procedure Flush (File : File_Type);
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 ----------------
kono
parents:
diff changeset
135 -- Exceptions --
kono
parents:
diff changeset
136 ----------------
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 Status_Error : exception renames IO_Exceptions.Status_Error;
kono
parents:
diff changeset
139 Mode_Error : exception renames IO_Exceptions.Mode_Error;
kono
parents:
diff changeset
140 Name_Error : exception renames IO_Exceptions.Name_Error;
kono
parents:
diff changeset
141 Use_Error : exception renames IO_Exceptions.Use_Error;
kono
parents:
diff changeset
142 Device_Error : exception renames IO_Exceptions.Device_Error;
kono
parents:
diff changeset
143 End_Error : exception renames IO_Exceptions.End_Error;
kono
parents:
diff changeset
144 Data_Error : exception renames IO_Exceptions.Data_Error;
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 private
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 -- The following procedures have a File_Type formal of mode IN OUT because
kono
parents:
diff changeset
149 -- they may close the original file. The Close operation may raise an
kono
parents:
diff changeset
150 -- exception, but in that case we want any assignment to the formal to
kono
parents:
diff changeset
151 -- be effective anyway, so it must be passed by reference (or the caller
kono
parents:
diff changeset
152 -- will be left with a dangling pointer).
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 pragma Export_Procedure
kono
parents:
diff changeset
155 (Internal => Close,
kono
parents:
diff changeset
156 External => "",
kono
parents:
diff changeset
157 Mechanism => Reference);
kono
parents:
diff changeset
158 pragma Export_Procedure
kono
parents:
diff changeset
159 (Internal => Delete,
kono
parents:
diff changeset
160 External => "",
kono
parents:
diff changeset
161 Mechanism => Reference);
kono
parents:
diff changeset
162 pragma Export_Procedure
kono
parents:
diff changeset
163 (Internal => Reset,
kono
parents:
diff changeset
164 External => "",
kono
parents:
diff changeset
165 Parameter_Types => (File_Type),
kono
parents:
diff changeset
166 Mechanism => Reference);
kono
parents:
diff changeset
167 pragma Export_Procedure
kono
parents:
diff changeset
168 (Internal => Reset,
kono
parents:
diff changeset
169 External => "",
kono
parents:
diff changeset
170 Parameter_Types => (File_Type, File_Mode),
kono
parents:
diff changeset
171 Mechanism => (File => Reference));
kono
parents:
diff changeset
172 pragma Export_Procedure
kono
parents:
diff changeset
173 (Internal => Set_Mode,
kono
parents:
diff changeset
174 External => "",
kono
parents:
diff changeset
175 Mechanism => (File => Reference));
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 package FCB renames System.File_Control_Block;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 -----------------------------
kono
parents:
diff changeset
180 -- Stream_IO Control Block --
kono
parents:
diff changeset
181 -----------------------------
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 type Operation is (Op_Read, Op_Write, Op_Other);
kono
parents:
diff changeset
184 -- Type used to record last operation (to optimize sequential operations)
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 type Stream_AFCB is new FCB.AFCB with record
kono
parents:
diff changeset
187 Index : Count := 1;
kono
parents:
diff changeset
188 -- Current Index value
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 File_Size : Stream_Element_Offset := -1;
kono
parents:
diff changeset
191 -- Cached value of File_Size, so that we do not keep recomputing it
kono
parents:
diff changeset
192 -- when not necessary (otherwise End_Of_File becomes gruesomely slow).
kono
parents:
diff changeset
193 -- A value of minus one means that there is no cached value.
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 Last_Op : Operation := Op_Other;
kono
parents:
diff changeset
196 -- Last operation performed on file, used to avoid unnecessary
kono
parents:
diff changeset
197 -- repositioning between successive read or write operations.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 Update_Mode : Boolean := False;
kono
parents:
diff changeset
200 -- Set if the mode is changed from write to read or vice versa.
kono
parents:
diff changeset
201 -- Indicates that the file has been reopened in update mode.
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 end record;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 type File_Type is access all Stream_AFCB;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 overriding function AFCB_Allocate
kono
parents:
diff changeset
208 (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 overriding procedure AFCB_Close (File : not null access Stream_AFCB);
kono
parents:
diff changeset
211 overriding procedure AFCB_Free (File : not null access Stream_AFCB);
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 overriding procedure Read
kono
parents:
diff changeset
214 (File : in out Stream_AFCB;
kono
parents:
diff changeset
215 Item : out Ada.Streams.Stream_Element_Array;
kono
parents:
diff changeset
216 Last : out Ada.Streams.Stream_Element_Offset);
kono
parents:
diff changeset
217 -- Read operation used when Stream_IO file is treated directly as Stream
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 overriding procedure Write
kono
parents:
diff changeset
220 (File : in out Stream_AFCB;
kono
parents:
diff changeset
221 Item : Ada.Streams.Stream_Element_Array);
kono
parents:
diff changeset
222 -- Write operation used when Stream_IO file is treated directly as Stream
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 end Ada.Streams.Stream_IO;