OSDN Git Service

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