OSDN Git Service

2008-05-27 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-sequio.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                    A D A . S E Q U E N T I A L _ I O                     --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- GNAT was originally developed  by the GNAT team at  New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
35 --                                                                          --
36 ------------------------------------------------------------------------------
37
38 with Ada.IO_Exceptions;
39
40 with System.Sequential_IO;
41
42 generic
43    type Element_Type (<>) is private;
44
45 package Ada.Sequential_IO is
46
47    pragma Compile_Time_Warning
48      (Element_Type'Has_Access_Values,
49       "Element_Type for Sequential_IO instance has access values");
50
51    pragma Compile_Time_Warning
52      (Element_Type'Has_Tagged_Values,
53       "Element_Type for Sequential_IO instance has tagged values");
54
55    type File_Type is limited private;
56
57    type File_Mode is (In_File, Out_File, Append_File);
58
59    --  The following representation clause allows the use of unchecked
60    --  conversion for rapid translation between the File_Mode type
61    --  used in this package and System.File_IO.
62
63    for File_Mode use
64      (In_File     => 0,  -- System.File_IO.File_Mode'Pos (In_File)
65       Out_File    => 2,  -- System.File_IO.File_Mode'Pos (Out_File)
66       Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
67
68    ---------------------
69    -- File management --
70    ---------------------
71
72    procedure Create
73      (File : in out File_Type;
74       Mode : File_Mode := Out_File;
75       Name : String := "";
76       Form : String := "");
77
78    procedure Open
79      (File : in out File_Type;
80       Mode : File_Mode;
81       Name : String;
82       Form : String := "");
83
84    procedure Close  (File : in out File_Type);
85    procedure Delete (File : in out File_Type);
86    procedure Reset  (File : in out File_Type; Mode : File_Mode);
87    procedure Reset  (File : in out File_Type);
88
89    function Mode    (File : File_Type) return File_Mode;
90    function Name    (File : File_Type) return String;
91    function Form    (File : File_Type) return String;
92
93    function Is_Open (File : File_Type) return Boolean;
94
95    ---------------------------------
96    -- Input and output operations --
97    ---------------------------------
98
99    procedure Read  (File : File_Type; Item : out Element_Type);
100    procedure Write (File : File_Type; Item : Element_Type);
101
102    function End_Of_File (File : File_Type) return Boolean;
103
104    ----------------
105    -- Exceptions --
106    ----------------
107
108    Status_Error : exception renames IO_Exceptions.Status_Error;
109    Mode_Error   : exception renames IO_Exceptions.Mode_Error;
110    Name_Error   : exception renames IO_Exceptions.Name_Error;
111    Use_Error    : exception renames IO_Exceptions.Use_Error;
112    Device_Error : exception renames IO_Exceptions.Device_Error;
113    End_Error    : exception renames IO_Exceptions.End_Error;
114    Data_Error   : exception renames IO_Exceptions.Data_Error;
115
116 private
117
118    --  The following procedures have a File_Type formal of mode IN OUT because
119    --  they may close the original file. The Close operation may raise an
120    --  exception, but in that case we want any assignment to the formal to
121    --  be effective anyway, so it must be passed by reference (or the caller
122    --  will be left with a dangling pointer).
123
124    pragma Export_Procedure
125      (Internal  => Close,
126       External  => "",
127       Mechanism => Reference);
128    pragma Export_Procedure
129      (Internal  => Delete,
130       External  => "",
131       Mechanism => Reference);
132    pragma Export_Procedure
133      (Internal        => Reset,
134       External        => "",
135       Parameter_Types => (File_Type),
136       Mechanism       => Reference);
137    pragma Export_Procedure
138      (Internal        => Reset,
139       External        => "",
140       Parameter_Types => (File_Type, File_Mode),
141       Mechanism       => (File => Reference));
142
143    type File_Type is new System.Sequential_IO.File_Type;
144
145    --  All subprograms are inlined
146
147    pragma Inline (Close);
148    pragma Inline (Create);
149    pragma Inline (Delete);
150    pragma Inline (End_Of_File);
151    pragma Inline (Form);
152    pragma Inline (Is_Open);
153    pragma Inline (Mode);
154    pragma Inline (Name);
155    pragma Inline (Open);
156    pragma Inline (Read);
157    pragma Inline (Reset);
158    pragma Inline (Write);
159
160 end Ada.Sequential_IO;