OSDN Git Service

PR 33870
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-stalib.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --              S Y S T E M . S T A N D A R D _ L I B R A R Y               --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2007, 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 --  This package is included in all programs. It contains declarations that
35 --  are required to be part of every Ada program. A special mechanism is
36 --  required to ensure that these are loaded, since it may be the case in
37 --  some programs that the only references to these required packages are
38 --  from C code or from code generated directly by Gigi, an in both cases
39 --  the binder is not aware of such references.
40
41 --  System.Standard_Library also includes data that must be present in every
42 --  program, in particular the definitions of all the standard and also some
43 --  subprograms that must be present in every program.
44
45 --  The binder unconditionally includes s-stalib.ali, which ensures that this
46 --  package and the packages it references are included in all Ada programs,
47 --  together with the included data.
48
49 pragma Warnings (Off);
50 pragma Compiler_Unit;
51 pragma Warnings (On);
52
53 pragma Polling (Off);
54 --  We must turn polling off for this unit, because otherwise we get
55 --  elaboration circularities with Ada.Exceptions if polling is on.
56
57 with System;
58 with Ada.Unchecked_Conversion;
59
60 package System.Standard_Library is
61    pragma Warnings (Off);
62    pragma Preelaborate_05;
63    pragma Warnings (On);
64
65    type Big_String_Ptr is access all String (Positive);
66    --  A non-fat pointer type for null terminated strings
67
68    function To_Ptr is
69      new Ada.Unchecked_Conversion (System.Address, Big_String_Ptr);
70
71    ---------------------------------------------
72    -- Type For Enumeration Image Index Tables --
73    ---------------------------------------------
74
75    --  Note: these types are declared at the start of this unit, since
76    --  they must appear before any enumeration types declared in this
77    --  unit. Note that the spec of system is already elaborated at
78    --  this point (since we are a child of system), which means that
79    --  enumeration types in package System cannot use these types.
80
81    type Image_Index_Table_8 is
82      array (Integer range <>) of Short_Short_Integer;
83    type Image_Index_Table_16 is
84      array (Integer range <>) of Short_Integer;
85    type Image_Index_Table_32 is
86      array (Integer range <>) of Integer;
87    --  These types are used to generate the index vector used for enumeration
88    --  type image tables. See spec of Exp_Imgv in the main GNAT sources for a
89    --  full description of the data structures that are used here.
90
91    -------------------------------------
92    -- Exception Declarations and Data --
93    -------------------------------------
94
95    type Raise_Action is access procedure;
96    --  A pointer to a procedure used in the Raise_Hook field
97
98    type Exception_Data;
99    type Exception_Data_Ptr is access all Exception_Data;
100    --  An equivalent of Exception_Id that is public
101
102    type Exception_Code is mod 2 ** Integer'Size;
103    --  A scalar value bound to some exception data. Typically used for
104    --  imported or exported exceptions on VMS. Having a separate type for this
105    --  is useful to enforce consistency throughout the various run-time units
106    --  handling such codes, and having it unsigned is the most appropriate
107    --  choice for it's currently single use on VMS.
108
109    --  ??? The construction in Cstand has no way to access the proper type
110    --  node for Exception_Code, and currently uses Standard_Unsigned as a
111    --  fallback. The representations shall match, and the size clause below
112    --  is aimed at ensuring that.
113
114    for Exception_Code'Size use Integer'Size;
115
116    --  The following record defines the underlying representation of exceptions
117
118    --  WARNING! Any changes to this may need to be reflectd in the following
119    --  locations in the compiler and runtime code:
120
121    --    1. The Internal_Exception routine in s-exctab.adb
122    --    2. The processing in gigi that tests Not_Handled_By_Others
123    --    3. Expand_N_Exception_Declaration in Exp_Ch11
124    --    4. The construction of the exception type in Cstand
125
126    type Exception_Data is record
127       Not_Handled_By_Others : Boolean;
128       --  Normally set False, indicating that the exception is handled in the
129       --  usual way by others (i.e. an others handler handles the exception).
130       --  Set True to indicate that this exception is not caught by others
131       --  handlers, but must be explicitly named in a handler. This latter
132       --  setting is currently used by the Abort_Signal.
133
134       Lang : Character;
135       --  A character indicating the language raising the exception.
136       --  Set to "A" for exceptions defined by an Ada program.
137       --  Set to "V" for imported VMS exceptions.
138
139       Name_Length : Natural;
140       --  Length of fully expanded name of exception
141
142       Full_Name : System.Address;
143       --  Fully expanded name of exception, null terminated
144       --  You can use To_Ptr to convert this to a string.
145
146       HTable_Ptr : Exception_Data_Ptr;
147       --  Hash table pointer used to link entries together in the hash table
148       --  built (by Register_Exception in s-exctab.adb) for converting between
149       --  identities and names.
150
151       Import_Code : Exception_Code;
152       --  Value for imported exceptions. Needed only for the handling of
153       --  Import/Export_Exception for the VMS case, but present in all
154       --  implementations (we might well extend this mechanism for other
155       --  systems in the future).
156
157       Raise_Hook : Raise_Action;
158       --  This field can be used to place a "hook" on an exception. If the
159       --  value is non-null, then it points to a procedure which is called
160       --  whenever the exception is raised. This call occurs immediately,
161       --  before any other actions taken by the raise (and in particular
162       --  before any unwinding of the stack occurs).
163    end record;
164
165    --  Definitions for standard predefined exceptions defined in Standard,
166
167    --  Why are the Nul's necessary here, seems like they should not be
168    --  required, since Gigi is supposed to add a Nul to each name ???
169
170    Constraint_Error_Name : constant String := "CONSTRAINT_ERROR" & ASCII.NUL;
171    Program_Error_Name    : constant String := "PROGRAM_ERROR"    & ASCII.NUL;
172    Storage_Error_Name    : constant String := "STORAGE_ERROR"    & ASCII.NUL;
173    Tasking_Error_Name    : constant String := "TASKING_ERROR"    & ASCII.NUL;
174    Abort_Signal_Name     : constant String := "_ABORT_SIGNAL"    & ASCII.NUL;
175
176    Numeric_Error_Name    : constant String := "NUMERIC_ERROR"    & ASCII.NUL;
177    --  This is used only in the Ada 83 case, but it is not worth having a
178    --  separate version of s-stalib.ads for use in Ada 83 mode.
179
180    Constraint_Error_Def : aliased Exception_Data :=
181      (Not_Handled_By_Others => False,
182       Lang                  => 'A',
183       Name_Length           => Constraint_Error_Name'Length,
184       Full_Name             => Constraint_Error_Name'Address,
185       HTable_Ptr            => null,
186       Import_Code           => 0,
187       Raise_Hook            => null);
188
189    Numeric_Error_Def : aliased Exception_Data :=
190      (Not_Handled_By_Others => False,
191       Lang                  => 'A',
192       Name_Length           => Numeric_Error_Name'Length,
193       Full_Name             => Numeric_Error_Name'Address,
194       HTable_Ptr            => null,
195       Import_Code           => 0,
196       Raise_Hook            => null);
197
198    Program_Error_Def : aliased Exception_Data :=
199      (Not_Handled_By_Others => False,
200       Lang                  => 'A',
201       Name_Length           => Program_Error_Name'Length,
202       Full_Name             => Program_Error_Name'Address,
203       HTable_Ptr            => null,
204       Import_Code           => 0,
205       Raise_Hook            => null);
206
207    Storage_Error_Def : aliased Exception_Data :=
208      (Not_Handled_By_Others => False,
209       Lang                  => 'A',
210       Name_Length           => Storage_Error_Name'Length,
211       Full_Name             => Storage_Error_Name'Address,
212       HTable_Ptr            => null,
213       Import_Code           => 0,
214       Raise_Hook            => null);
215
216    Tasking_Error_Def : aliased Exception_Data :=
217      (Not_Handled_By_Others => False,
218       Lang                  => 'A',
219       Name_Length           => Tasking_Error_Name'Length,
220       Full_Name             => Tasking_Error_Name'Address,
221       HTable_Ptr            => null,
222       Import_Code           => 0,
223       Raise_Hook            => null);
224
225    Abort_Signal_Def : aliased Exception_Data :=
226      (Not_Handled_By_Others => True,
227       Lang                  => 'A',
228       Name_Length           => Abort_Signal_Name'Length,
229       Full_Name             => Abort_Signal_Name'Address,
230       HTable_Ptr            => null,
231       Import_Code           => 0,
232       Raise_Hook            => null);
233
234    pragma Export (C, Constraint_Error_Def, "constraint_error");
235    pragma Export (C, Numeric_Error_Def,    "numeric_error");
236    pragma Export (C, Program_Error_Def,    "program_error");
237    pragma Export (C, Storage_Error_Def,    "storage_error");
238    pragma Export (C, Tasking_Error_Def,    "tasking_error");
239    pragma Export (C, Abort_Signal_Def,     "_abort_signal");
240
241    Local_Partition_ID : Natural := 0;
242    --  This variable contains the local Partition_ID that will be used when
243    --  building exception occurrences. In distributed mode, it will be
244    --  set by each partition to the correct value during the elaboration.
245
246    type Exception_Trace_Kind is
247      (RM_Convention,
248       --  No particular trace is requested, only unhandled exceptions
249       --  in the environment task (following the RM) will be printed.
250       --  This is the default behavior.
251
252       Every_Raise,
253       --  Denotes every possible raise event, either explicit or due to
254       --  a specific language rule, within the context of a task or not.
255
256       Unhandled_Raise
257       --  Denotes the raise events corresponding to exceptions for which
258       --  there is no user defined handler.
259      );
260    --  Provide a way to denote different kinds of automatic traces related
261    --  to exceptions that can be requested.
262
263    Exception_Trace : Exception_Trace_Kind := RM_Convention;
264    pragma Atomic (Exception_Trace);
265    --  By default, follow the RM convention
266
267    -----------------
268    -- Subprograms --
269    -----------------
270
271    procedure Abort_Undefer_Direct;
272    pragma Inline (Abort_Undefer_Direct);
273    --  A little procedure that just calls Abort_Undefer.all, for use in
274    --  clean up procedures, which only permit a simple subprogram name.
275
276    procedure Adafinal;
277    --  Performs the Ada Runtime finalization the first time it is invoked.
278    --  All subsequent calls are ignored.
279
280 end System.Standard_Library;