OSDN Git Service

2011-08-03 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-except-2005.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                       A D A . E X C E P T I O N S                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2011, 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 version of Ada.Exceptions fully supports both Ada 95 and Ada 2005.
33 --  It is used in all situations except for the build of the compiler and
34 --  other basic tools. For these latter builds, we use an Ada 95-only version.
35
36 --  The reason for this splitting off of a separate version is that bootstrap
37 --  compilers often will be used that do not support Ada 2005 features, and
38 --  Ada.Exceptions is part of the compiler sources.
39
40 pragma Style_Checks (All_Checks);
41 --  No subprogram ordering check, due to logical grouping
42
43 pragma Polling (Off);
44 --  We must turn polling off for this unit, because otherwise we get
45 --  elaboration circularities with System.Exception_Tables.
46
47 with System;                  use System;
48 with System.Exceptions;       use System.Exceptions;
49 with System.Standard_Library; use System.Standard_Library;
50 with System.Soft_Links;       use System.Soft_Links;
51 with System.WCh_Con;          use System.WCh_Con;
52 with System.WCh_StW;          use System.WCh_StW;
53
54 package body Ada.Exceptions is
55
56    pragma Suppress (All_Checks);
57    --  We definitely do not want exceptions occurring within this unit, or
58    --  we are in big trouble. If an exceptional situation does occur, better
59    --  that it not be raised, since raising it can cause confusing chaos.
60
61    -----------------------
62    -- Local Subprograms --
63    -----------------------
64
65    --  Note: the exported subprograms in this package body are called directly
66    --  from C clients using the given external name, even though they are not
67    --  technically visible in the Ada sense.
68
69    function Code_Address_For_AAA return System.Address;
70    function Code_Address_For_ZZZ return System.Address;
71    --  Return start and end of procedures in this package
72    --
73    --  These procedures are used to provide exclusion bounds in
74    --  calls to Call_Chain at exception raise points from this unit. The
75    --  purpose is to arrange for the exception tracebacks not to include
76    --  frames from routines involved in the raise process, as these are
77    --  meaningless from the user's standpoint.
78    --
79    --  For these bounds to be meaningful, we need to ensure that the object
80    --  code for the routines involved in processing a raise is located after
81    --  the object code Code_Address_For_AAA and before the object code
82    --  Code_Address_For_ZZZ. This will indeed be the case as long as the
83    --  following rules are respected:
84    --
85    --  1) The bodies of the subprograms involved in processing a raise
86    --     are located after the body of Code_Address_For_AAA and before the
87    --     body of Code_Address_For_ZZZ.
88    --
89    --  2) No pragma Inline applies to any of these subprograms, as this
90    --     could delay the corresponding assembly output until the end of
91    --     the unit.
92
93    procedure Call_Chain (Excep : EOA);
94    --  Store up to Max_Tracebacks in Excep, corresponding to the current
95    --  call chain.
96
97    function Image (Index : Integer) return String;
98    --  Return string image corresponding to Index
99
100    procedure To_Stderr (S : String);
101    pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
102    --  Little routine to output string to stderr that is also used
103    --  in the tasking run time.
104
105    procedure To_Stderr (C : Character);
106    pragma Inline (To_Stderr);
107    pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
108    --  Little routine to output a character to stderr, used by some of
109    --  the separate units below.
110
111    package Exception_Data is
112
113       ---------------------------------
114       -- Exception messages routines --
115       ---------------------------------
116
117       procedure Set_Exception_C_Msg
118         (Id     : Exception_Id;
119          Msg1   : System.Address;
120          Line   : Integer        := 0;
121          Column : Integer        := 0;
122          Msg2   : System.Address := System.Null_Address);
123       --  This routine is called to setup the exception referenced by the
124       --  Current_Excep field in the TSD to contain the indicated Id value
125       --  and message. Msg1 is a null terminated string which is generated
126       --  as the exception message. If line is non-zero, then a colon and
127       --  the decimal representation of this integer is appended to the
128       --  message. Ditto for Column. When Msg2 is non-null, a space and this
129       --  additional null terminated string is added to the message.
130
131       procedure Set_Exception_Msg
132         (Id      : Exception_Id;
133          Message : String);
134       --  This routine is called to setup the exception referenced by the
135       --  Current_Excep field in the TSD to contain the indicated Id value
136       --  and message. Message is a string which is generated as the
137       --  exception message.
138
139       --------------------------------------
140       -- Exception information subprogram --
141       --------------------------------------
142
143       function Exception_Information (X : Exception_Occurrence) return String;
144       --  The format of the exception information is as follows:
145       --
146       --    Exception_Name: <exception name> (as in Exception_Name)
147       --    Message: <message> (only if Exception_Message is empty)
148       --    PID=nnnn (only if != 0)
149       --    Call stack traceback locations:  (only if at least one location)
150       --    <0xyyyyyyyy 0xyyyyyyyy ...>      (is recorded)
151       --
152       --  The lines are separated by a ASCII.LF character.
153       --  The nnnn is the partition Id given as decimal digits.
154       --  The 0x... line represents traceback program counter locations, in
155       --  execution order with the first one being the exception location. It
156       --  is present only
157       --
158       --  The Exception_Name and Message lines are omitted in the abort
159       --  signal case, since this is not really an exception.
160
161       --  !! If the format of the generated string is changed, please note
162       --  !! that an equivalent modification to the routine String_To_EO must
163       --  !! be made to preserve proper functioning of the stream attributes.
164
165       ---------------------------------------
166       -- Exception backtracing subprograms --
167       ---------------------------------------
168
169       --  What is automatically output when exception tracing is on is the
170       --  usual exception information with the call chain backtrace possibly
171       --  tailored by a backtrace decorator. Modifying Exception_Information
172       --  itself is not a good idea because the decorated output is completely
173       --  out of control and would break all our code related to the streaming
174       --  of exceptions.  We then provide an alternative function to compute
175       --  the possibly tailored output, which is equivalent if no decorator is
176       --  currently set:
177
178       function Tailored_Exception_Information
179         (X : Exception_Occurrence) return String;
180       --  Exception information to be output in the case of automatic tracing
181       --  requested through GNAT.Exception_Traces.
182       --
183       --  This is the same as Exception_Information if no backtrace decorator
184       --  is currently in place. Otherwise, this is Exception_Information with
185       --  the call chain raw addresses replaced by the result of a call to the
186       --  current decorator provided with the call chain addresses.
187
188       pragma Export
189         (Ada, Tailored_Exception_Information,
190            "__gnat_tailored_exception_information");
191       --  This is currently used by System.Tasking.Stages
192
193    end Exception_Data;
194
195    package Exception_Traces is
196
197       use Exception_Data;
198       --  Imports Tailored_Exception_Information
199
200       ----------------------------------------------
201       -- Run-Time Exception Notification Routines --
202       ----------------------------------------------
203
204       --  These subprograms provide a common run-time interface to trigger the
205       --  actions required when an exception is about to be propagated (e.g.
206       --  user specified actions or output of exception information). They are
207       --  exported to be usable by the Ada exception handling personality
208       --  routine when the GCC 3 mechanism is used.
209
210       procedure Notify_Handled_Exception;
211       pragma Export
212         (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
213       --  This routine is called for a handled occurrence is about to be
214       --  propagated.
215
216       procedure Notify_Unhandled_Exception;
217       pragma Export
218         (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
219       --  This routine is called when an unhandled occurrence is about to be
220       --  propagated.
221
222       procedure Unhandled_Exception_Terminate;
223       pragma No_Return (Unhandled_Exception_Terminate);
224       --  This procedure is called to terminate execution following an
225       --  unhandled exception. The exception information, including
226       --  traceback if available is output, and execution is then
227       --  terminated. Note that at the point where this routine is
228       --  called, the stack has typically been destroyed.
229
230    end Exception_Traces;
231
232    package Exception_Propagation is
233
234       use Exception_Traces;
235       --  Imports Notify_Unhandled_Exception and
236       --  Unhandled_Exception_Terminate
237
238       ------------------------------------
239       -- Exception propagation routines --
240       ------------------------------------
241
242       procedure Setup_Exception
243         (Excep    : EOA;
244          Current  : EOA;
245          Reraised : Boolean := False);
246       --  Perform the necessary operations to prepare the propagation of Excep
247       --  in a task where Current is the current occurrence. Excep is assumed
248       --  to be a valid (non null) pointer.
249       --
250       --  This should be called before any (re-)setting of the current
251       --  occurrence. Any such (re-)setting shall take care *not* to clobber
252       --  the Private_Data component.
253       --
254       --  Having Current provided as an argument (instead of retrieving it via
255       --  Get_Current_Excep internally) is required to allow one task to setup
256       --  an exception for another task, which is used by Transfer_Occurrence.
257
258       procedure Propagate_Exception
259         (E                   : Exception_Id;
260          From_Signal_Handler : Boolean);
261       pragma No_Return (Propagate_Exception);
262       --  This procedure propagates the exception represented by the occurrence
263       --  referenced by Current_Excep in the TSD for the current task.
264
265    end Exception_Propagation;
266
267    package Stream_Attributes is
268
269       --------------------------------
270       -- Stream attributes routines --
271       --------------------------------
272
273       function EId_To_String (X : Exception_Id) return String;
274       function String_To_EId (S : String) return Exception_Id;
275       --  Functions for implementing Exception_Id stream attributes
276
277       function EO_To_String (X : Exception_Occurrence) return String;
278       function String_To_EO (S : String) return Exception_Occurrence;
279       --  Functions for implementing Exception_Occurrence stream
280       --  attributes
281
282    end Stream_Attributes;
283
284    procedure Raise_Current_Excep (E : Exception_Id);
285    pragma No_Return (Raise_Current_Excep);
286    pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
287    --  This is a simple wrapper to Exception_Propagation.Propagate_Exception
288    --  setting the From_Signal_Handler argument to False.
289    --
290    --  This external name for Raise_Current_Excep is historical, and probably
291    --  should be changed but for now we keep it, because gdb and gigi know
292    --  about it.
293
294    procedure Raise_Exception_No_Defer
295       (E : Exception_Id; Message : String := "");
296    pragma Export
297     (Ada, Raise_Exception_No_Defer,
298      "ada__exceptions__raise_exception_no_defer");
299    pragma No_Return (Raise_Exception_No_Defer);
300    --  Similar to Raise_Exception, but with no abort deferral
301
302    procedure Raise_With_Msg (E : Exception_Id);
303    pragma No_Return (Raise_With_Msg);
304    pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
305    --  Raises an exception with given exception id value. A message
306    --  is associated with the raise, and has already been stored in the
307    --  exception occurrence referenced by the Current_Excep in the TSD.
308    --  Abort is deferred before the raise call.
309
310    procedure Raise_With_Location_And_Msg
311      (E : Exception_Id;
312       F : System.Address;
313       L : Integer;
314       C : Integer := 0;
315       M : System.Address := System.Null_Address);
316    pragma No_Return (Raise_With_Location_And_Msg);
317    --  Raise an exception with given exception id value. A filename and line
318    --  number is associated with the raise and is stored in the exception
319    --  occurrence and in addition a column and a string message M may be
320    --  appended to this (if not null/0).
321
322    procedure Raise_Constraint_Error
323      (File : System.Address;
324       Line : Integer);
325    pragma No_Return (Raise_Constraint_Error);
326    pragma Export
327      (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
328    --  Raise constraint error with file:line information
329
330    procedure Raise_Constraint_Error_Msg
331      (File   : System.Address;
332       Line   : Integer;
333       Column : Integer;
334       Msg    : System.Address);
335    pragma No_Return (Raise_Constraint_Error_Msg);
336    pragma Export
337      (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
338    --  Raise constraint error with file:line:col + msg information
339
340    procedure Raise_Program_Error
341      (File : System.Address;
342       Line : Integer);
343    pragma No_Return (Raise_Program_Error);
344    pragma Export
345      (C, Raise_Program_Error, "__gnat_raise_program_error");
346    --  Raise program error with file:line information
347
348    procedure Raise_Program_Error_Msg
349      (File : System.Address;
350       Line : Integer;
351       Msg  : System.Address);
352    pragma No_Return (Raise_Program_Error_Msg);
353    pragma Export
354      (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
355    --  Raise program error with file:line + msg information
356
357    procedure Raise_Storage_Error
358      (File : System.Address;
359       Line : Integer);
360    pragma No_Return (Raise_Storage_Error);
361    pragma Export
362      (C, Raise_Storage_Error, "__gnat_raise_storage_error");
363    --  Raise storage error with file:line information
364
365    procedure Raise_Storage_Error_Msg
366      (File : System.Address;
367       Line : Integer;
368       Msg  : System.Address);
369    pragma No_Return (Raise_Storage_Error_Msg);
370    pragma Export
371      (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
372    --  Raise storage error with file:line + reason msg information
373
374    --  The exception raising process and the automatic tracing mechanism rely
375    --  on some careful use of flags attached to the exception occurrence. The
376    --  graph below illustrates the relations between the Raise_ subprograms
377    --  and identifies the points where basic flags such as Exception_Raised
378    --  are initialized.
379    --
380    --  (i) signs indicate the flags initialization points. R stands for Raise,
381    --  W for With, and E for Exception.
382    --
383    --                   R_No_Msg    R_E   R_Pe  R_Ce  R_Se
384    --                       |        |     |     |     |
385    --                       +--+  +--+     +---+ | +---+
386    --                          |  |            | | |
387    --     R_E_No_Defer(i)    R_W_Msg(i)       R_W_Loc
388    --           |               |              |   |
389    --           +------------+  |  +-----------+   +--+
390    --                        |  |  |                  |
391    --                        |  |  |             Set_E_C_Msg(i)
392    --                        |  |  |
393    --                   Raise_Current_Excep
394
395    procedure Reraise;
396    pragma No_Return (Reraise);
397    pragma Export (C, Reraise, "__gnat_reraise");
398    --  Reraises the exception referenced by the Current_Excep field of
399    --  the TSD (all fields of this exception occurrence are set). Abort
400    --  is deferred before the reraise operation.
401
402    --  Save_Occurrence variations: As the management of the private data
403    --  attached to occurrences is delicate, whether or not pointers to such
404    --  data has to be copied in various situations is better made explicit.
405    --  The following procedures provide an internal interface to help making
406    --  this explicit.
407
408    procedure Save_Occurrence_No_Private
409      (Target : out Exception_Occurrence;
410       Source : Exception_Occurrence);
411    --  Copy all the components of Source to Target, except the
412    --  Private_Data pointer.
413
414    procedure Transfer_Occurrence
415      (Target : Exception_Occurrence_Access;
416       Source : Exception_Occurrence);
417    pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
418    --  Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
419    --  to setup Target from Source as an exception to be propagated in the
420    --  caller task. Target is expected to be a pointer to the fixed TSD
421    --  occurrence for this task.
422
423    -----------------------------
424    -- Run-Time Check Routines --
425    -----------------------------
426
427    --  These routines raise a specific exception with a reason message
428    --  attached. The parameters are the file name and line number in each
429    --  case. The names are keyed to the codes defined in types.ads and
430    --  a-types.h (for example, the name Rcheck_05 refers to the Reason
431    --  RT_Exception_Code'Val (5)).
432
433    procedure Rcheck_00 (File : System.Address; Line : Integer);
434    procedure Rcheck_01 (File : System.Address; Line : Integer);
435    procedure Rcheck_02 (File : System.Address; Line : Integer);
436    procedure Rcheck_03 (File : System.Address; Line : Integer);
437    procedure Rcheck_04 (File : System.Address; Line : Integer);
438    procedure Rcheck_05 (File : System.Address; Line : Integer);
439    procedure Rcheck_06 (File : System.Address; Line : Integer);
440    procedure Rcheck_07 (File : System.Address; Line : Integer);
441    procedure Rcheck_08 (File : System.Address; Line : Integer);
442    procedure Rcheck_09 (File : System.Address; Line : Integer);
443    procedure Rcheck_10 (File : System.Address; Line : Integer);
444    procedure Rcheck_11 (File : System.Address; Line : Integer);
445    procedure Rcheck_12 (File : System.Address; Line : Integer);
446    procedure Rcheck_13 (File : System.Address; Line : Integer);
447    procedure Rcheck_14 (File : System.Address; Line : Integer);
448    procedure Rcheck_15 (File : System.Address; Line : Integer);
449    procedure Rcheck_16 (File : System.Address; Line : Integer);
450    procedure Rcheck_17 (File : System.Address; Line : Integer);
451    procedure Rcheck_18 (File : System.Address; Line : Integer);
452    procedure Rcheck_19 (File : System.Address; Line : Integer);
453    procedure Rcheck_20 (File : System.Address; Line : Integer);
454    procedure Rcheck_21 (File : System.Address; Line : Integer);
455    procedure Rcheck_22 (File : System.Address; Line : Integer);
456    procedure Rcheck_23 (File : System.Address; Line : Integer);
457    procedure Rcheck_24 (File : System.Address; Line : Integer);
458    procedure Rcheck_25 (File : System.Address; Line : Integer);
459    procedure Rcheck_26 (File : System.Address; Line : Integer);
460    procedure Rcheck_27 (File : System.Address; Line : Integer);
461    procedure Rcheck_28 (File : System.Address; Line : Integer);
462    procedure Rcheck_29 (File : System.Address; Line : Integer);
463    procedure Rcheck_30 (File : System.Address; Line : Integer);
464    procedure Rcheck_31 (File : System.Address; Line : Integer);
465    procedure Rcheck_32 (File : System.Address; Line : Integer);
466    procedure Rcheck_33 (File : System.Address; Line : Integer);
467    procedure Rcheck_34 (File : System.Address; Line : Integer);
468
469    procedure Rcheck_00_Ext
470      (File : System.Address; Line, Column : Integer);
471    procedure Rcheck_05_Ext
472      (File : System.Address; Line, Column, Index, First, Last : Integer);
473    procedure Rcheck_06_Ext
474      (File : System.Address; Line, Column, Index, First, Last : Integer);
475    procedure Rcheck_12_Ext
476      (File : System.Address; Line, Column, Index, First, Last : Integer);
477
478    pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
479    pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
480    pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
481    pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
482    pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
483    pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
484    pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
485    pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
486    pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
487    pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
488    pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
489    pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
490    pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
491    pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
492    pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
493    pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
494    pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
495    pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
496    pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
497    pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
498    pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
499    pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
500    pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
501    pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
502    pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
503    pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
504    pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
505    pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
506    pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
507    pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
508    pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
509    pragma Export (C, Rcheck_31, "__gnat_rcheck_31");
510    pragma Export (C, Rcheck_32, "__gnat_rcheck_32");
511    pragma Export (C, Rcheck_33, "__gnat_rcheck_33");
512    pragma Export (C, Rcheck_34, "__gnat_rcheck_34");
513
514    pragma Export (C, Rcheck_00_Ext, "__gnat_rcheck_00_ext");
515    pragma Export (C, Rcheck_05_Ext, "__gnat_rcheck_05_ext");
516    pragma Export (C, Rcheck_06_Ext, "__gnat_rcheck_06_ext");
517    pragma Export (C, Rcheck_12_Ext, "__gnat_rcheck_12_ext");
518
519    --  None of these procedures ever returns (they raise an exception!). By
520    --  using pragma No_Return, we ensure that any junk code after the call,
521    --  such as normal return epilog stuff, can be eliminated).
522
523    pragma No_Return (Rcheck_00);
524    pragma No_Return (Rcheck_01);
525    pragma No_Return (Rcheck_02);
526    pragma No_Return (Rcheck_03);
527    pragma No_Return (Rcheck_04);
528    pragma No_Return (Rcheck_05);
529    pragma No_Return (Rcheck_06);
530    pragma No_Return (Rcheck_07);
531    pragma No_Return (Rcheck_08);
532    pragma No_Return (Rcheck_09);
533    pragma No_Return (Rcheck_10);
534    pragma No_Return (Rcheck_11);
535    pragma No_Return (Rcheck_12);
536    pragma No_Return (Rcheck_13);
537    pragma No_Return (Rcheck_14);
538    pragma No_Return (Rcheck_15);
539    pragma No_Return (Rcheck_16);
540    pragma No_Return (Rcheck_17);
541    pragma No_Return (Rcheck_18);
542    pragma No_Return (Rcheck_19);
543    pragma No_Return (Rcheck_20);
544    pragma No_Return (Rcheck_21);
545    pragma No_Return (Rcheck_22);
546    pragma No_Return (Rcheck_23);
547    pragma No_Return (Rcheck_24);
548    pragma No_Return (Rcheck_25);
549    pragma No_Return (Rcheck_26);
550    pragma No_Return (Rcheck_27);
551    pragma No_Return (Rcheck_28);
552    pragma No_Return (Rcheck_29);
553    pragma No_Return (Rcheck_30);
554    pragma No_Return (Rcheck_32);
555    pragma No_Return (Rcheck_33);
556    pragma No_Return (Rcheck_34);
557
558    pragma No_Return (Rcheck_00_Ext);
559    pragma No_Return (Rcheck_05_Ext);
560    pragma No_Return (Rcheck_06_Ext);
561    pragma No_Return (Rcheck_12_Ext);
562
563    ---------------------------------------------
564    -- Reason Strings for Run-Time Check Calls --
565    ---------------------------------------------
566
567    --  These strings are null-terminated and are used by Rcheck_nn. The
568    --  strings correspond to the definitions for Types.RT_Exception_Code.
569
570    use ASCII;
571
572    Rmsg_00 : constant String := "access check failed"              & NUL;
573    Rmsg_01 : constant String := "access parameter is null"         & NUL;
574    Rmsg_02 : constant String := "discriminant check failed"        & NUL;
575    Rmsg_03 : constant String := "divide by zero"                   & NUL;
576    Rmsg_04 : constant String := "explicit raise"                   & NUL;
577    Rmsg_05 : constant String := "index check failed"               & NUL;
578    Rmsg_06 : constant String := "invalid data"                     & NUL;
579    Rmsg_07 : constant String := "length check failed"              & NUL;
580    Rmsg_08 : constant String := "null Exception_Id"                & NUL;
581    Rmsg_09 : constant String := "null-exclusion check failed"      & NUL;
582    Rmsg_10 : constant String := "overflow check failed"            & NUL;
583    Rmsg_11 : constant String := "partition check failed"           & NUL;
584    Rmsg_12 : constant String := "range check failed"               & NUL;
585    Rmsg_13 : constant String := "tag check failed"                 & NUL;
586    Rmsg_14 : constant String := "access before elaboration"        & NUL;
587    Rmsg_15 : constant String := "accessibility check failed"       & NUL;
588    Rmsg_16 : constant String := "attempt to take address of"       &
589                                 " intrinsic subprogram"            & NUL;
590    Rmsg_17 : constant String := "all guards closed"                & NUL;
591    Rmsg_18 : constant String := "improper use of generic subtype"  &
592                                 " with predicate"                  & NUL;
593    Rmsg_19 : constant String := "Current_Task referenced in entry" &
594                                 " body"                            & NUL;
595    Rmsg_20 : constant String := "duplicated entry address"         & NUL;
596    Rmsg_21 : constant String := "explicit raise"                   & NUL;
597    Rmsg_22 : constant String := "finalize/adjust raised exception" & NUL;
598    Rmsg_23 : constant String := "implicit return with No_Return"   & NUL;
599    Rmsg_24 : constant String := "misaligned address value"         & NUL;
600    Rmsg_25 : constant String := "missing return"                   & NUL;
601    Rmsg_26 : constant String := "overlaid controlled object"       & NUL;
602    Rmsg_27 : constant String := "potentially blocking operation"   & NUL;
603    Rmsg_28 : constant String := "stubbed subprogram called"        & NUL;
604    Rmsg_29 : constant String := "unchecked union restriction"      & NUL;
605    Rmsg_30 : constant String := "actual/returned class-wide"       &
606                                 " value not transportable"         & NUL;
607    Rmsg_31 : constant String := "empty storage pool"               & NUL;
608    Rmsg_32 : constant String := "explicit raise"                   & NUL;
609    Rmsg_33 : constant String := "infinite recursion"               & NUL;
610    Rmsg_34 : constant String := "object too large"                 & NUL;
611
612    -----------------------
613    -- Polling Interface --
614    -----------------------
615
616    type Unsigned is mod 2 ** 32;
617
618    Counter : Unsigned := 0;
619    pragma Warnings (Off, Counter);
620    --  This counter is provided for convenience. It can be used in Poll to
621    --  perform periodic but not systematic operations.
622
623    procedure Poll is separate;
624    --  The actual polling routine is separate, so that it can easily
625    --  be replaced with a target dependent version.
626
627    --------------------------
628    -- Code_Address_For_AAA --
629    --------------------------
630
631    --  This function gives us the start of the PC range for addresses
632    --  within the exception unit itself. We hope that gigi/gcc keep all the
633    --  procedures in their original order!
634
635    function Code_Address_For_AAA return System.Address is
636    begin
637       --  We are using a label instead of merely using
638       --  Code_Address_For_AAA'Address because on some platforms the latter
639       --  does not yield the address we want, but the address of a stub or of
640       --  a descriptor instead. This is the case at least on Alpha-VMS and
641       --  PA-HPUX.
642
643       <<Start_Of_AAA>>
644       return Start_Of_AAA'Address;
645    end Code_Address_For_AAA;
646
647    ----------------
648    -- Call_Chain --
649    ----------------
650
651    procedure Call_Chain (Excep : EOA) is separate;
652    --  The actual Call_Chain routine is separate, so that it can easily
653    --  be dummied out when no exception traceback information is needed.
654
655    ------------------------------
656    -- Current_Target_Exception --
657    ------------------------------
658
659    function Current_Target_Exception return Exception_Occurrence is
660    begin
661       return Null_Occurrence;
662    end Current_Target_Exception;
663
664    -------------------
665    -- EId_To_String --
666    -------------------
667
668    function EId_To_String (X : Exception_Id) return String
669      renames Stream_Attributes.EId_To_String;
670
671    ------------------
672    -- EO_To_String --
673    ------------------
674
675    --  We use the null string to represent the null occurrence, otherwise
676    --  we output the Exception_Information string for the occurrence.
677
678    function EO_To_String (X : Exception_Occurrence) return String
679      renames Stream_Attributes.EO_To_String;
680
681    ------------------------
682    -- Exception_Identity --
683    ------------------------
684
685    function Exception_Identity
686      (X : Exception_Occurrence) return Exception_Id
687    is
688    begin
689       --  Note that the following test used to be here for the original
690       --  Ada 95 semantics, but these were modified by AI-241 to require
691       --  returning Null_Id instead of raising Constraint_Error.
692
693       --  if X.Id = Null_Id then
694       --     raise Constraint_Error;
695       --  end if;
696
697       return X.Id;
698    end Exception_Identity;
699
700    ---------------------------
701    -- Exception_Information --
702    ---------------------------
703
704    function Exception_Information (X : Exception_Occurrence) return String is
705    begin
706       if X.Id = Null_Id then
707          raise Constraint_Error;
708       end if;
709
710       return Exception_Data.Exception_Information (X);
711    end Exception_Information;
712
713    -----------------------
714    -- Exception_Message --
715    -----------------------
716
717    function Exception_Message (X : Exception_Occurrence) return String is
718    begin
719       if X.Id = Null_Id then
720          raise Constraint_Error;
721       end if;
722
723       return X.Msg (1 .. X.Msg_Length);
724    end Exception_Message;
725
726    --------------------
727    -- Exception_Name --
728    --------------------
729
730    function Exception_Name (Id : Exception_Id) return String is
731    begin
732       if Id = null then
733          raise Constraint_Error;
734       end if;
735
736       return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
737    end Exception_Name;
738
739    function Exception_Name (X : Exception_Occurrence) return String is
740    begin
741       return Exception_Name (X.Id);
742    end Exception_Name;
743
744    ---------------------------
745    -- Exception_Name_Simple --
746    ---------------------------
747
748    function Exception_Name_Simple (X : Exception_Occurrence) return String is
749       Name : constant String := Exception_Name (X);
750       P    : Natural;
751
752    begin
753       P := Name'Length;
754       while P > 1 loop
755          exit when Name (P - 1) = '.';
756          P := P - 1;
757       end loop;
758
759       --  Return result making sure lower bound is 1
760
761       declare
762          subtype Rname is String (1 .. Name'Length - P + 1);
763       begin
764          return Rname (Name (P .. Name'Length));
765       end;
766    end Exception_Name_Simple;
767
768    --------------------
769    -- Exception_Data --
770    --------------------
771
772    package body Exception_Data is separate;
773    --  This package can be easily dummied out if we do not want the
774    --  basic support for exception messages (such as in Ada 83).
775
776    ---------------------------
777    -- Exception_Propagation --
778    ---------------------------
779
780    package body Exception_Propagation is separate;
781    --  Depending on the actual exception mechanism used (front-end or
782    --  back-end based), the implementation will differ, which is why this
783    --  package is separated.
784
785    ----------------------
786    -- Exception_Traces --
787    ----------------------
788
789    package body Exception_Traces is separate;
790    --  Depending on the underlying support for IO the implementation
791    --  will differ. Moreover we would like to dummy out this package
792    --  in case we do not want any exception tracing support. This is
793    --  why this package is separated.
794
795    -----------------------
796    -- Stream Attributes --
797    -----------------------
798
799    package body Stream_Attributes is separate;
800    --  This package can be easily dummied out if we do not want the
801    --  support for streaming Exception_Ids and Exception_Occurrences.
802
803    ----------------------------
804    -- Raise_Constraint_Error --
805    ----------------------------
806
807    procedure Raise_Constraint_Error (File : System.Address; Line : Integer) is
808    begin
809       Raise_With_Location_And_Msg (Constraint_Error_Def'Access, File, Line);
810    end Raise_Constraint_Error;
811
812    --------------------------------
813    -- Raise_Constraint_Error_Msg --
814    --------------------------------
815
816    procedure Raise_Constraint_Error_Msg
817      (File   : System.Address;
818       Line   : Integer;
819       Column : Integer;
820       Msg    : System.Address)
821    is
822    begin
823       Raise_With_Location_And_Msg
824         (Constraint_Error_Def'Access, File, Line, Column, Msg);
825    end Raise_Constraint_Error_Msg;
826
827    -------------------------
828    -- Raise_Current_Excep --
829    -------------------------
830
831    procedure Raise_Current_Excep (E : Exception_Id) is
832    begin
833       Debug_Raise_Exception (E => SSL.Exception_Data_Ptr (E));
834       Exception_Propagation.Propagate_Exception
835         (E => E, From_Signal_Handler => False);
836    end Raise_Current_Excep;
837
838    ---------------------
839    -- Raise_Exception --
840    ---------------------
841
842    procedure Raise_Exception
843      (E       : Exception_Id;
844       Message : String := "")
845    is
846       EF : Exception_Id := E;
847
848    begin
849       --  Raise CE if E = Null_ID (AI-446)
850
851       if E = null then
852          EF := Constraint_Error'Identity;
853       end if;
854
855       --  Go ahead and raise appropriate exception
856
857       Exception_Data.Set_Exception_Msg (EF, Message);
858       Abort_Defer.all;
859       Raise_Current_Excep (EF);
860    end Raise_Exception;
861
862    ----------------------------
863    -- Raise_Exception_Always --
864    ----------------------------
865
866    procedure Raise_Exception_Always
867      (E       : Exception_Id;
868       Message : String := "")
869    is
870    begin
871       Exception_Data.Set_Exception_Msg (E, Message);
872       Abort_Defer.all;
873       Raise_Current_Excep (E);
874    end Raise_Exception_Always;
875
876    -------------------------------------
877    -- Raise_From_Controlled_Operation --
878    -------------------------------------
879
880    procedure Raise_From_Controlled_Operation
881      (X : Ada.Exceptions.Exception_Occurrence)
882    is
883       Prev_Exc  : constant EOA := Get_Current_Excep.all;
884
885    begin
886       --  We're raising an exception during finalization. If the finalization
887       --  was triggered by an abort, as indicated by Not_Handled_By_Others,
888       --  then we don't want to raise Program_Error; we want to continue with
889       --  the Abort_Signal exception. Note that the original exception
890       --  occurrence that triggered the finalization is saved before calling
891       --  the Finalize procedures, and then restored afterward, so in the case
892       --  of abort, the original Abort_Signal will be the current one.
893
894       if Prev_Exc.Id /= null and then Prev_Exc.Id.Not_Handled_By_Others then
895          Raise_Current_Excep (Prev_Exc.Id);
896
897       --  Otherwise, raise Program_Error
898
899       else
900          declare
901             Prefix             : constant String := "adjust/finalize raised ";
902             Orig_Msg           : constant String := Exception_Message (X);
903             Orig_Prefix_Length : constant Natural :=
904               Integer'Min (Prefix'Length, Orig_Msg'Length);
905             Orig_Prefix        : String renames Orig_Msg
906               (Orig_Msg'First .. Orig_Msg'First + Orig_Prefix_Length - 1);
907
908          begin
909             --  Message already has the proper prefix, just re-reraise
910
911             if Orig_Prefix = Prefix then
912                Raise_Exception_No_Defer
913                  (E       => Program_Error'Identity,
914                   Message => Orig_Msg);
915
916             else
917                declare
918                   New_Msg  : constant String := Prefix & Exception_Name (X);
919
920                begin
921                   --  No message present, just provide our own
922
923                   if Orig_Msg = "" then
924                      Raise_Exception_No_Defer
925                        (E       => Program_Error'Identity,
926                         Message => New_Msg);
927
928                   --  Message present, add informational prefix
929
930                   else
931                      Raise_Exception_No_Defer
932                        (E       => Program_Error'Identity,
933                         Message => New_Msg & ": " & Orig_Msg);
934                   end if;
935                end;
936             end if;
937          end;
938       end if;
939    end Raise_From_Controlled_Operation;
940
941    -------------------------------
942    -- Raise_From_Signal_Handler --
943    -------------------------------
944
945    procedure Raise_From_Signal_Handler
946      (E : Exception_Id;
947       M : System.Address)
948    is
949    begin
950       Exception_Data.Set_Exception_C_Msg (E, M);
951       Abort_Defer.all;
952       Debug_Raise_Exception (E => SSL.Exception_Data_Ptr (E));
953       Exception_Propagation.Propagate_Exception
954         (E => E, From_Signal_Handler => True);
955    end Raise_From_Signal_Handler;
956
957    -------------------------
958    -- Raise_Program_Error --
959    -------------------------
960
961    procedure Raise_Program_Error
962      (File : System.Address;
963       Line : Integer)
964    is
965    begin
966       Raise_With_Location_And_Msg (Program_Error_Def'Access, File, Line);
967    end Raise_Program_Error;
968
969    -----------------------------
970    -- Raise_Program_Error_Msg --
971    -----------------------------
972
973    procedure Raise_Program_Error_Msg
974      (File : System.Address;
975       Line : Integer;
976       Msg  : System.Address)
977    is
978    begin
979       Raise_With_Location_And_Msg
980         (Program_Error_Def'Access, File, Line, M => Msg);
981    end Raise_Program_Error_Msg;
982
983    -------------------------
984    -- Raise_Storage_Error --
985    -------------------------
986
987    procedure Raise_Storage_Error
988      (File : System.Address;
989       Line : Integer)
990    is
991    begin
992       Raise_With_Location_And_Msg (Storage_Error_Def'Access, File, Line);
993    end Raise_Storage_Error;
994
995    -----------------------------
996    -- Raise_Storage_Error_Msg --
997    -----------------------------
998
999    procedure Raise_Storage_Error_Msg
1000      (File : System.Address;
1001       Line : Integer;
1002       Msg  : System.Address)
1003    is
1004    begin
1005       Raise_With_Location_And_Msg
1006         (Storage_Error_Def'Access, File, Line, M => Msg);
1007    end Raise_Storage_Error_Msg;
1008
1009    ---------------------------------
1010    -- Raise_With_Location_And_Msg --
1011    ---------------------------------
1012
1013    procedure Raise_With_Location_And_Msg
1014      (E : Exception_Id;
1015       F : System.Address;
1016       L : Integer;
1017       C : Integer := 0;
1018       M : System.Address := System.Null_Address)
1019    is
1020    begin
1021       Exception_Data.Set_Exception_C_Msg (E, F, L, C, M);
1022       Abort_Defer.all;
1023       Raise_Current_Excep (E);
1024    end Raise_With_Location_And_Msg;
1025
1026    --------------------
1027    -- Raise_With_Msg --
1028    --------------------
1029
1030    procedure Raise_With_Msg (E : Exception_Id) is
1031       Excep : constant EOA := Get_Current_Excep.all;
1032
1033    begin
1034       Exception_Propagation.Setup_Exception (Excep, Excep);
1035
1036       Excep.Exception_Raised := False;
1037       Excep.Id               := E;
1038       Excep.Num_Tracebacks   := 0;
1039       Excep.Cleanup_Flag     := False;
1040       Excep.Pid              := Local_Partition_ID;
1041       Abort_Defer.all;
1042       Raise_Current_Excep (E);
1043    end Raise_With_Msg;
1044
1045    -----------
1046    -- Image --
1047    -----------
1048
1049    function Image (Index : Integer) return String is
1050       Result : constant String := Integer'Image (Index);
1051    begin
1052       if Result (1) = ' ' then
1053          return Result (2 .. Result'Last);
1054       else
1055          return Result;
1056       end if;
1057    end Image;
1058
1059    --------------------------------------
1060    -- Calls to Run-Time Check Routines --
1061    --------------------------------------
1062
1063    procedure Rcheck_00 (File : System.Address; Line : Integer) is
1064    begin
1065       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_00'Address);
1066    end Rcheck_00;
1067
1068    procedure Rcheck_01 (File : System.Address; Line : Integer) is
1069    begin
1070       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_01'Address);
1071    end Rcheck_01;
1072
1073    procedure Rcheck_02 (File : System.Address; Line : Integer) is
1074    begin
1075       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_02'Address);
1076    end Rcheck_02;
1077
1078    procedure Rcheck_03 (File : System.Address; Line : Integer) is
1079    begin
1080       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_03'Address);
1081    end Rcheck_03;
1082
1083    procedure Rcheck_04 (File : System.Address; Line : Integer) is
1084    begin
1085       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_04'Address);
1086    end Rcheck_04;
1087
1088    procedure Rcheck_05 (File : System.Address; Line : Integer) is
1089    begin
1090       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_05'Address);
1091    end Rcheck_05;
1092
1093    procedure Rcheck_06 (File : System.Address; Line : Integer) is
1094    begin
1095       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_06'Address);
1096    end Rcheck_06;
1097
1098    procedure Rcheck_07 (File : System.Address; Line : Integer) is
1099    begin
1100       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_07'Address);
1101    end Rcheck_07;
1102
1103    procedure Rcheck_08 (File : System.Address; Line : Integer) is
1104    begin
1105       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_08'Address);
1106    end Rcheck_08;
1107
1108    procedure Rcheck_09 (File : System.Address; Line : Integer) is
1109    begin
1110       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_09'Address);
1111    end Rcheck_09;
1112
1113    procedure Rcheck_10 (File : System.Address; Line : Integer) is
1114    begin
1115       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_10'Address);
1116    end Rcheck_10;
1117
1118    procedure Rcheck_11 (File : System.Address; Line : Integer) is
1119    begin
1120       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_11'Address);
1121    end Rcheck_11;
1122
1123    procedure Rcheck_12 (File : System.Address; Line : Integer) is
1124    begin
1125       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_12'Address);
1126    end Rcheck_12;
1127
1128    procedure Rcheck_13 (File : System.Address; Line : Integer) is
1129    begin
1130       Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_13'Address);
1131    end Rcheck_13;
1132
1133    procedure Rcheck_14 (File : System.Address; Line : Integer) is
1134    begin
1135       Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1136    end Rcheck_14;
1137
1138    procedure Rcheck_15 (File : System.Address; Line : Integer) is
1139    begin
1140       Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1141    end Rcheck_15;
1142
1143    procedure Rcheck_16 (File : System.Address; Line : Integer) is
1144    begin
1145       Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1146    end Rcheck_16;
1147
1148    procedure Rcheck_17 (File : System.Address; Line : Integer) is
1149    begin
1150       Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1151    end Rcheck_17;
1152
1153    procedure Rcheck_18 (File : System.Address; Line : Integer) is
1154    begin
1155       Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1156    end Rcheck_18;
1157
1158    procedure Rcheck_19 (File : System.Address; Line : Integer) is
1159    begin
1160       Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1161    end Rcheck_19;
1162
1163    procedure Rcheck_20 (File : System.Address; Line : Integer) is
1164    begin
1165       Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1166    end Rcheck_20;
1167
1168    procedure Rcheck_21 (File : System.Address; Line : Integer) is
1169    begin
1170       Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1171    end Rcheck_21;
1172
1173    procedure Rcheck_22 (File : System.Address; Line : Integer) is
1174    begin
1175       Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1176    end Rcheck_22;
1177
1178    procedure Rcheck_23 (File : System.Address; Line : Integer) is
1179    begin
1180       Raise_Program_Error_Msg (File, Line, Rmsg_23'Address);
1181    end Rcheck_23;
1182
1183    procedure Rcheck_24 (File : System.Address; Line : Integer) is
1184    begin
1185       Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1186    end Rcheck_24;
1187
1188    procedure Rcheck_25 (File : System.Address; Line : Integer) is
1189    begin
1190       Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1191    end Rcheck_25;
1192
1193    procedure Rcheck_26 (File : System.Address; Line : Integer) is
1194    begin
1195       Raise_Program_Error_Msg (File, Line, Rmsg_26'Address);
1196    end Rcheck_26;
1197
1198    procedure Rcheck_27 (File : System.Address; Line : Integer) is
1199    begin
1200       Raise_Program_Error_Msg (File, Line, Rmsg_27'Address);
1201    end Rcheck_27;
1202
1203    procedure Rcheck_28 (File : System.Address; Line : Integer) is
1204    begin
1205       Raise_Program_Error_Msg (File, Line, Rmsg_28'Address);
1206    end Rcheck_28;
1207
1208    procedure Rcheck_29 (File : System.Address; Line : Integer) is
1209    begin
1210       Raise_Program_Error_Msg (File, Line, Rmsg_29'Address);
1211    end Rcheck_29;
1212
1213    procedure Rcheck_30 (File : System.Address; Line : Integer) is
1214    begin
1215       Raise_Program_Error_Msg (File, Line, Rmsg_30'Address);
1216    end Rcheck_30;
1217
1218    procedure Rcheck_31 (File : System.Address; Line : Integer) is
1219    begin
1220       Raise_Storage_Error_Msg (File, Line, Rmsg_31'Address);
1221    end Rcheck_31;
1222
1223    procedure Rcheck_32 (File : System.Address; Line : Integer) is
1224    begin
1225       Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address);
1226    end Rcheck_32;
1227
1228    procedure Rcheck_33 (File : System.Address; Line : Integer) is
1229    begin
1230       Raise_Storage_Error_Msg (File, Line, Rmsg_33'Address);
1231    end Rcheck_33;
1232
1233    procedure Rcheck_34 (File : System.Address; Line : Integer) is
1234    begin
1235       Raise_Storage_Error_Msg (File, Line, Rmsg_34'Address);
1236    end Rcheck_34;
1237
1238    procedure Rcheck_00_Ext (File : System.Address; Line, Column : Integer) is
1239    begin
1240       Raise_Constraint_Error_Msg (File, Line, Column, Rmsg_00'Address);
1241    end Rcheck_00_Ext;
1242
1243    procedure Rcheck_05_Ext
1244      (File : System.Address; Line, Column, Index, First, Last : Integer)
1245    is
1246       Msg : constant String :=
1247               Rmsg_05 (Rmsg_05'First .. Rmsg_05'Last - 1) & ASCII.LF &
1248               "index " & Image (Index) & " not in " & Image (First) &
1249               ".." & Image (Last) & ASCII.NUL;
1250    begin
1251       Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1252    end Rcheck_05_Ext;
1253
1254    procedure Rcheck_06_Ext
1255      (File : System.Address; Line, Column, Index, First, Last : Integer)
1256    is
1257       Msg : constant String :=
1258               Rmsg_06 (Rmsg_06'First .. Rmsg_06'Last - 1) & ASCII.LF &
1259               "value " & Image (Index) & " not in " & Image (First) &
1260               ".." & Image (Last) & ASCII.NUL;
1261    begin
1262       Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1263    end Rcheck_06_Ext;
1264
1265    procedure Rcheck_12_Ext
1266      (File : System.Address; Line, Column, Index, First, Last : Integer)
1267    is
1268       Msg : constant String :=
1269               Rmsg_12 (Rmsg_12'First .. Rmsg_12'Last - 1) & ASCII.LF &
1270               "value " & Image (Index) & " not in " & Image (First) &
1271               ".." & Image (Last) & ASCII.NUL;
1272    begin
1273       Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1274    end Rcheck_12_Ext;
1275
1276    -------------
1277    -- Reraise --
1278    -------------
1279
1280    procedure Reraise is
1281       Excep : constant EOA := Get_Current_Excep.all;
1282    begin
1283       Abort_Defer.all;
1284       Exception_Propagation.Setup_Exception (Excep, Excep, Reraised => True);
1285       Raise_Current_Excep (Excep.Id);
1286    end Reraise;
1287
1288    ------------------------
1289    -- Reraise_Occurrence --
1290    ------------------------
1291
1292    procedure Reraise_Occurrence (X : Exception_Occurrence) is
1293    begin
1294       if X.Id /= null then
1295          Abort_Defer.all;
1296          Exception_Propagation.Setup_Exception
1297            (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1298          Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1299          Raise_Current_Excep (X.Id);
1300       end if;
1301    end Reraise_Occurrence;
1302
1303    -------------------------------
1304    -- Reraise_Occurrence_Always --
1305    -------------------------------
1306
1307    procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1308    begin
1309       Abort_Defer.all;
1310       Exception_Propagation.Setup_Exception
1311         (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1312       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1313       Raise_Current_Excep (X.Id);
1314    end Reraise_Occurrence_Always;
1315
1316    ---------------------------------
1317    -- Reraise_Occurrence_No_Defer --
1318    ---------------------------------
1319
1320    procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1321    begin
1322       Exception_Propagation.Setup_Exception
1323         (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1324       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1325       Raise_Current_Excep (X.Id);
1326    end Reraise_Occurrence_No_Defer;
1327
1328    ---------------------
1329    -- Save_Occurrence --
1330    ---------------------
1331
1332    procedure Save_Occurrence
1333      (Target : out Exception_Occurrence;
1334       Source : Exception_Occurrence)
1335    is
1336    begin
1337       Save_Occurrence_No_Private (Target, Source);
1338    end Save_Occurrence;
1339
1340    function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1341       Target : constant EOA := new Exception_Occurrence;
1342    begin
1343       Save_Occurrence (Target.all, Source);
1344       return Target;
1345    end Save_Occurrence;
1346
1347    --------------------------------
1348    -- Save_Occurrence_No_Private --
1349    --------------------------------
1350
1351    procedure Save_Occurrence_No_Private
1352      (Target : out Exception_Occurrence;
1353       Source : Exception_Occurrence)
1354    is
1355    begin
1356       Target.Id             := Source.Id;
1357       Target.Msg_Length     := Source.Msg_Length;
1358       Target.Num_Tracebacks := Source.Num_Tracebacks;
1359       Target.Pid            := Source.Pid;
1360       Target.Cleanup_Flag   := Source.Cleanup_Flag;
1361
1362       Target.Msg (1 .. Target.Msg_Length) :=
1363         Source.Msg (1 .. Target.Msg_Length);
1364
1365       Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1366         Source.Tracebacks (1 .. Target.Num_Tracebacks);
1367    end Save_Occurrence_No_Private;
1368
1369    -------------------------
1370    -- Transfer_Occurrence --
1371    -------------------------
1372
1373    procedure Transfer_Occurrence
1374      (Target : Exception_Occurrence_Access;
1375       Source : Exception_Occurrence)
1376    is
1377    begin
1378       --  Setup Target as an exception to be propagated in the calling task
1379       --  (rendezvous-wise), taking care not to clobber the associated private
1380       --  data.  Target is expected to be a pointer to the calling task's
1381       --  fixed TSD occurrence, which is very different from Get_Current_Excep
1382       --  here because this subprogram is called from the called task.
1383
1384       Exception_Propagation.Setup_Exception (Target, Target);
1385       Save_Occurrence_No_Private (Target.all, Source);
1386    end Transfer_Occurrence;
1387
1388    -------------------
1389    -- String_To_EId --
1390    -------------------
1391
1392    function String_To_EId (S : String) return Exception_Id
1393      renames Stream_Attributes.String_To_EId;
1394
1395    ------------------
1396    -- String_To_EO --
1397    ------------------
1398
1399    function String_To_EO (S : String) return Exception_Occurrence
1400      renames Stream_Attributes.String_To_EO;
1401
1402    ------------------------------
1403    -- Raise_Exception_No_Defer --
1404    ------------------------------
1405
1406    procedure Raise_Exception_No_Defer
1407      (E       : Exception_Id;
1408       Message : String := "")
1409    is
1410    begin
1411       Exception_Data.Set_Exception_Msg (E, Message);
1412
1413       --  Do not call Abort_Defer.all, as specified by the spec
1414
1415       Raise_Current_Excep (E);
1416    end Raise_Exception_No_Defer;
1417
1418    ---------------
1419    -- To_Stderr --
1420    ---------------
1421
1422    procedure To_Stderr (C : Character) is
1423       type int is new Integer;
1424
1425       procedure put_char_stderr (C : int);
1426       pragma Import (C, put_char_stderr, "put_char_stderr");
1427
1428    begin
1429       put_char_stderr (Character'Pos (C));
1430    end To_Stderr;
1431
1432    procedure To_Stderr (S : String) is
1433    begin
1434       for J in S'Range loop
1435          if S (J) /= ASCII.CR then
1436             To_Stderr (S (J));
1437          end if;
1438       end loop;
1439    end To_Stderr;
1440
1441    -------------------------
1442    -- Wide_Exception_Name --
1443    -------------------------
1444
1445    WC_Encoding : Character;
1446    pragma Import (C, WC_Encoding, "__gl_wc_encoding");
1447    --  Encoding method for source, as exported by binder
1448
1449    function Wide_Exception_Name
1450      (Id : Exception_Id) return Wide_String
1451    is
1452       S : constant String := Exception_Name (Id);
1453       W : Wide_String (1 .. S'Length);
1454       L : Natural;
1455    begin
1456       String_To_Wide_String
1457         (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1458       return W (1 .. L);
1459    end Wide_Exception_Name;
1460
1461    function Wide_Exception_Name
1462      (X : Exception_Occurrence) return Wide_String
1463    is
1464       S : constant String := Exception_Name (X);
1465       W : Wide_String (1 .. S'Length);
1466       L : Natural;
1467    begin
1468       String_To_Wide_String
1469         (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1470       return W (1 .. L);
1471    end Wide_Exception_Name;
1472
1473    ----------------------------
1474    -- Wide_Wide_Exception_Name --
1475    -----------------------------
1476
1477    function Wide_Wide_Exception_Name
1478      (Id : Exception_Id) return Wide_Wide_String
1479    is
1480       S : constant String := Exception_Name (Id);
1481       W : Wide_Wide_String (1 .. S'Length);
1482       L : Natural;
1483    begin
1484       String_To_Wide_Wide_String
1485         (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1486       return W (1 .. L);
1487    end Wide_Wide_Exception_Name;
1488
1489    function Wide_Wide_Exception_Name
1490      (X : Exception_Occurrence) return Wide_Wide_String
1491    is
1492       S : constant String := Exception_Name (X);
1493       W : Wide_Wide_String (1 .. S'Length);
1494       L : Natural;
1495    begin
1496       String_To_Wide_Wide_String
1497         (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1498       return W (1 .. L);
1499    end Wide_Wide_Exception_Name;
1500
1501    --------------------------
1502    -- Code_Address_For_ZZZ --
1503    --------------------------
1504
1505    --  This function gives us the end of the PC range for addresses
1506    --  within the exception unit itself. We hope that gigi/gcc keeps all the
1507    --  procedures in their original order!
1508
1509    function Code_Address_For_ZZZ return System.Address is
1510    begin
1511       <<Start_Of_ZZZ>>
1512       return Start_Of_ZZZ'Address;
1513    end Code_Address_For_ZZZ;
1514
1515 end Ada.Exceptions;